嗨,我有一个数据帧列表,数据如下:
到2018年的元素1子集
structure(list(year = c("2018", "2018", "2018", "2018", "2018",
"2018", "2018", "2018", "2018", "2018", "2018", "2018"), month = c(1,
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), Avdischarge = c(906.5947917,
511.2469444, 364.0697222, 268.3026389, 141.5931944, 142.0445486,
37.53111111, 34.68916667, 35.50809028, 26.94083333, 40.400381945,
312.0436806), IndustrialCompound = c(0.729166666666667, 0.815789473684211,
0.818181818181818, 0.771428571428571, 0.736842105263158, 0.761904761904762,
0.780487804878049, 0.829268292682927, 0.8, 0.780487804878049,
0.738095238095238, 0.731707317073171), Pharmaceutical = c(0.145833333333333,
0.105263157894737, 0.113636363636364, 0.142857142857143, 0.131578947368421,
0.119047619047619, 0.121951219512195, 0.0975609756097561, 0.114285714285714,
0.146341463414634, 0.166666666666667, 0.195121951219512), Pesticide = c(0.125,
0.0789473684210526, 0.0681818181818182, 0.0857142857142857, 0.131578947368421,
0.119047619047619, 0.0975609756097561, 0.0731707317073171, 0.0857142857142857,
0.0731707317073171, 0.0952380952380952, 0.0731707317073171),
TotalOvershootings = c(0.48, 0.558823529411765, 0.619718309859155,
0.538461538461538, 0.612903225806452, 0.591549295774648,
0.561643835616438, 0.554054054054054, 0.538461538461538,
0.577464788732394, 0.617647058823529, 0.694915254237288)), row.names = 37:48, class = "data.frame")
我想绘制放电图,所以我用
a <- ggplot(subset(counts[["HEE"]], year==2018), aes(x=month)) +
geom_line(aes(y= Avdischarge, group=1), color='royalblue1', size=1.5, alpha=0.8) +
scale_x_continuous(breaks= counts[["HEE"]][["month"]])+
scale_y_continuous(breaks = counts[["HEE"]][["Avdischarge"]])
我得到了这个
1。为什么我的y轴显示更多值?我只想要放电的12个值。可能是因为子集,并且还显示了其他年份的放电?我如何只为2018年设置?
基本上我想得到这样的东西(只是蓝线)
只有放电的记录值在y轴上,并且它们之间的距离在图中相同。 我几个月前做了这个,甚至使用了相同的代码,但没有scale_y_continuous,我得到了结果。我不知道为什么它不会再这样绘制了。
答案 0 :(得分:1)
我认为问题出在您的breaks
争论中。这对我有用:
ggplot(subset(dta, year==2018), aes(x=month)) +
geom_line(aes(y= Avdischarge, group=1), color='royalblue1', size=1.5, alpha=0.8) +
scale_y_continuous(breaks = seq(20, 1000, by=50))
我不确定您的counts[["HEE"]][["Avdischarge"]]
是什么,但是您只需要指定要显示的实际值即可(例如20, 70, 120, ...
)