当前位置: 首页 > 滚动 > >正文

作图时行列名中包含空格报错的处理方法

来源:腾讯云    时间:2023-03-17 01:02:45


(资料图片)

title: "作图时行列名中包含空格的处理方法"

output: html_document

date: "2023-03-14"

当作图时行列名中包含了空格等特殊字符时,R语言会报错,如下

library(ggplot2)dat <- iriscolnames(dat)[1] <- "a b"ggplot(dat,aes(a b,Sepal.Width))+  geom_point()
## Error: :4:18: unexpected symbol## 3: colnames(dat)[1] <- "a b"## 4: ggplot(dat,aes(a b##                     ^

将包含空格的行列名加上(反引号,英文输入模式下按“~”键)可以解决报错的问题如下

library(ggplot2)dat <- iriscolnames(dat)[1] <- "a b"ggplot(dat,aes(`a b`,Sepal.Width))+  geom_point()

引用自生信技能树

X 关闭

推荐内容

最近更新

Copyright ©  2015-2022 南方餐饮网版权所有  备案号:粤ICP备18023326号-21   联系邮箱:855 729 8@qq.com