【发布时间】:2016-11-18 11:50:14
【问题描述】:
我已经使用以下命令构建了一个包含每月温度数据的图。在这里,我需要添加一个具有定义形状(16、17、18...)、线型(1,1,2,...)和标签(1977、1978、1979...)的图例。我尝试了不同的方法,但没有运气认为没有导致任何错误。
这里是我的一部分数据
structure(list(month = structure(1:12, .Label = c("Jan", "Feb",
"Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov",
"Dec"), class = "factor"), X1977 = c(10.3, 11.8, 15.4, 18.7,
20.3, 22, 23.5, 24.5, 20.1, 17.2, 15.2, 16.5), X1978 = c(10.3,
8, 10.8, 16.9, 20.2, 20.3, 20, 20, 17.9, 16.4, 11.4, 12.9), X1979 = c(13.9,
12, 13.4, 17.5, 19.6, 20.3, 19.3, 19.3, 18.3, 16.1, 14.5, 10.6
)), .Names = c("month", "X1977", "X1978", "X1979"), class = "data.frame",row.names = c(NA,
-12L))
p <- ggplot(t.df, aes(month, X1977))
p
p <-p + geom_point(aes(month, X1977),shape=16) + geom_line(aes(x=1:12, y= X1977))
p <- p+ geom_point(aes(month, X1978),shape=17) + geom_line(aes(x=1:12, y= X1978))
p <- p+ geom_point(aes(month, X1979),shape=18) + geom_line(aes(x=1:12, y= X1979), linetype=2)
p2 <- p+ labs(x="Month", y="Mean Temperature")
p2
p2 + theme(legend.position = "right")+
scale_fill_manual(labels=c("1977", "1978", "1979"))+
scale_linetype_manual(1,1,2)+ scale_shape_manual(16,17,19)
# this code does not yield error but legend is not added on the plot
【问题讨论】:
-
你能分享一个小样本可重现的数据吗?
-
scale_shape_manual(values = c(16,17,19)) 正确的调用方式?同样适用于 linetype_manual()
-
您好,我在帖子中添加了一部分数据。