[英]How to change the NA value in barplot?
when I try to plot df
I find NA in the barplot.当我尝试绘制
df
时,我在条形图中找到了 NA。 I can't understand why.我不明白为什么。 Here is
df
这是
df
dput(df)
structure(list(Cancer.type = c(" BLCA", " BLCA", " BLCA", "BRCA",
"BRCA", "BRCA", "COAD", "COAD", "COAD", "ESCA", "ESCA", "ESCA",
"GBM", "GBM", "GBM", "KIRC", "KIRC", "KIRC", "LIHC", "LIHC",
"LIHC", "LUAD", "LUAD", "LUAD", "LUSC", "LUSC", "LUSC", "PRAD",
"PRAD", "PRAD", "STAD", "STAD", "STAD", "THCA", "THCA", "THCA",
"UCEC", "UCEC", "UCEC"), Number.of.genes = c(4L, 5L, 7L, 8L,
6L, 2L, 1L, 10L, 5L, 3L, 5L, 8L, 2L, 4L, 10L, 2L, 8L, 6L, 5L,
5L, 6L, 5L, 8L, 3L, 4L, 8L, 4L, 4L, 6L, 6L, 2L, 5L, 9L, 8L, 3L,
5L, 4L, 3L, 9L), Condition = c("Down ", "Up", "ns", "Down ",
"Up", "ns", "Down ", "Up", "ns", "Down ", "Up", "ns", "Down ",
"Up", "ns", "Down ", "Up", "ns", "Down ", "Up", "ns", "Down ",
"Up", "ns", "Down ", "Up", "ns", "Down ", "Up", "ns", "Down ",
"Up", "ns", "Down ", "Up", "ns", "Down ", "Up", "ns")), class = "data.frame", row.names = c(NA,
-39L))
Here is my script这是我的脚本
ggplot(df,aes(fill = factor(Condition, levels = c('Down','Up','ns')),
y = Number.of.genes, x =Cancer.type)) +
geom_bar(position="stack", stat="identity")+theme_bw()+
theme(axis.text.x = element_text(size = 10, angle = 45, hjust = 1, colour = 'black'))+
scale_fill_manual(values=c("seagreen2", "deepskyblue3",'goldenrod1'))+
labs(fill = 'Condition', x = NULL)
Thanks for any help.谢谢你的帮助。
In your Condition
column, the Down
actually has a trailing space.在您的
Condition
列中, Down
实际上有一个尾随空格。 So you can do 3 things:所以你可以做三件事:
df$Condition <- gsub(' ', '', df$Condition)
levels()
levels()
中添加空间ggplot(df,aes(fill = factor(Condition, levels = c('Down ','Up','ns'))
levels
argumentlevels
参数ggplot(df,aes(fill = factor(Condition)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.