我有以下数据帧prop_data
:
structure(list(Month = structure(1:10, levels = c("January",
"February", "March", "April", "May", "June", "July", "August",
"September", "October", "November", "December"), class = "factor"),
`Count false` = c(3211L, 2293L, 2051L, 1689L, 1203L, 580L,
638L, 394L, 227L, 108L), False = c(0.946918313181952, 0.965880370682393,
0.948220064724919, 0.964041095890411, 0.961630695443645,
0.952380952380952, 0.987616099071207, 0.985, 0.934156378600823,
0.931034482758621), `Count true` = c(180L, 81L, 112L, 63L,
48L, 29L, 8L, 6L, 16L, 8L), True = c(0.0530816868180478,
0.0341196293176074, 0.0517799352750809, 0.035958904109589,
0.0383693045563549, 0.0476190476190476, 0.0123839009287926,
0.015, 0.065843621399177, 0.0689655172413793)), class = "data.frame", row.names = c(NA,
-10L))
我想用不同的 colored颜色 和标签在同一张图中画出变量False
和True
.我想用ggplot2
.无论如何,下面的代码
library(ggplot2)
ggplot(prop_data, aes(x = Month)) +
geom_line(aes(y = `False`, color = "False"), size = 1.2) +
geom_line(aes(y = `True`, color = "True"), size = 1.2) +
labs(title = "Trend", x = "Month", y = "Proportions") +
scale_color_manual(values = c("False" = "blue", "True" = "red")) +
theme_minimal()
不起作用(图形为空).