Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从data.frame在ggplot图例中添加信息_R_Dataframe_Ggplot2 - Fatal编程技术网

从data.frame在ggplot图例中添加信息

从data.frame在ggplot图例中添加信息,r,dataframe,ggplot2,R,Dataframe,Ggplot2,我想在图例中添加具有此值的传感器的信息 这是我的密码: z <- data.frame( a=c("sensor 1","sensor 2","sensor 3","sensor 4","sensor 5","sensor 6","sensor 7","sensor 8"), b=c(50, 60, 70, 20,90,110,30,100) ) cxc <- ggplot(z, aes(x=a, y=b, fill=factor(b)))

我想在图例中添加具有此值的传感器的信息

这是我的密码:

z <- data.frame(
       a=c("sensor 1","sensor 2","sensor 3","sensor 4","sensor 5","sensor 6","sensor 7","sensor 8"), 
       b=c(50, 60, 70, 20,90,110,30,100)
     )

cxc <- ggplot(z, aes(x=a, y=b, fill=factor(b))) + 
         geom_bar(width = 1,stat="identity",colour = "black")  + 
         scale_fill_brewer(palette="Blues",type = "seq")+
         geom_text(aes(y = b/2,label = b),color = "red",size = 5)
cxc + coord_polar() + 
  theme_linedraw() + 
  theme(axis.ticks =element_blank(), axis.text.y =element_blank(), axis.title=element_blank(), axis.text.x=element_text(size = 12,angle = 45)) +
  guides(fill = guide_legend(title = "Value and sensor"))

z使用
labels
参数来
scale\u fill\u brewer
,并
order
按正确顺序排列标签

cxc <- ggplot(z, aes(x=a, y=b, fill=factor(b))) + 
  geom_bar(width = 1,stat="identity",colour = "black")  + 
  scale_fill_brewer(palette="Blues",type = "seq", labels = paste0(z$b, " (", z$a, ")")[order(z$b)])+
  geom_text(aes(y = b/2,label = b),color = "red",size = 5)
cxc + coord_polar() + 
  theme_linedraw() + 
  theme(axis.ticks =element_blank(), axis.text.y =element_blank(), axis.title=element_blank(), axis.text.x=element_text(size = 12,angle = 45)) +
  guides(fill = guide_legend(title = "Value and sensor"))

cxc您可以使用
labels
参数
scale\u fill\u brewer
@RichardTelford是的,但问题是当我放置
scale\u fill\u brewer(labels=z$a)
时,我得到了文本,但没有正确的文本作为值。我不知道怎样才能在没有手写的情况下将传感器正确地放置在数值上。