[英]Change text in legend base r
我想更改圖例中的文本,我還沒有解決如何做到這一點。 例如,將 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)
您只需為參數legend.text
提供一個帶有圖例文本的向量(每種顏色一個):
barplot(as.matrix(df), beside = TRUE, legend.text = c("C", "D", "E"))
如果您想進一步設置圖例樣式,您需要將參數放入命名列表中,並將其傳遞給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.