我有这段代码:
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
?我希望它是“有活动”和“没有活动”。
答案 0 :(得分:2)
这应该回答你的问题:
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))
这将是情节: