简体   繁体   English

更改图例库中的文本 r

[英]Change text in legend base r

I want to change the text in the legend, I have not come around how to do that.我想更改图例中的文本,我还没有解决如何做到这一点。 For exampe change A and B to D and C. Any suggestions?例如,将 A 和 B 更改为 D 和 C。有什么建议吗?

A <- c(10,5,5)
B <- c(30,10,10)

df <- cbind(A,B)

df <- t(df)

as.matrix(df)

barplot(df, beside=TRUE, legend=TRUE)

You simply supply a vector with the legend text (one for each color) to the argument legend.text :您只需为参数legend.text提供一个带有图例文本的向量(每种颜色一个):

barplot(as.matrix(df), beside = TRUE, legend.text = c("C", "D", "E"))

If you want to style the legend any further you need to put arguments inside a named list and pass it to the args.legend argument (look at ?legend ) for further arguments.如果您想进一步设置图例样式,您需要将参数放入命名列表中,并将其传递给args.legend参数(查看?legend )以获得更多参数。

df <- data.frame(A = c(10,5,5),
                 B = c(30,10,10))

barplot(as.matrix(df), beside = TRUE, legend.text = c("C", "D", "E"), args.legend = list(x = "bottomright"))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM