我想在图例中添加哪个传感器具有此值的信息。
这是我的代码:
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"))
我想在传说中这样写:
我希望保留这种颜色和图形样式。
答案 0 :(得分:3)
使用labels
参数scale_fill_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"))