![](/img/trans.png)
[英]ggplot2: How to adjust fill colour in a boxplot (and change legend text)?
[英]How to change the text in the colour legend of ggplot2
我有以下代碼:
ggplot(databoth, aes(withxstep)) +
geom_point(aes(y = withnassoc, colour = "withnassoc"), size = 2.8) +
geom_point(aes(y = withoutnassoc, colour = "withoutnassoc"), size = 1 ) +
labs(colour = "Legend") +
labs(x = "Time") +
labs(y = "N associations")
如何修改withnassoc
和withoutnassoc
? 我希望它是“有活動”和“無活動”。
這應該可以回答您的問題:
ggplot(databoth, aes(withxstep)) +
geom_point(aes(y = withnassoc, colour = "withnassoc"), size = 2.8) +
geom_point(aes(y = withoutnassoc, colour = "withoutnassoc"), size = 1 ) +
labs(colour = "Legend", x = "Time", y = "N associations") +
scale_color_manual(values = c("red", "blue"),
labels = c("With Activities", "Without activities"))
對於此示例數據集:
exampledata <- structure(list(withxstep = structure(c(4L, 3L, 2L, 1L),
.Label = c("2017-06-27", "2017-06-28", "2017-06-29", "2017-06-30"), class = "factor"),
withnassoc = c(1, 2, 3, 4), withoutnassoc = c(5, 6, 7, 8)), .Names = c("withxstep",
"withnassoc", "withoutnassoc"), class = "data.frame", row.names = c(NA,-4L))
這將是情節:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.