我正在尝试绘制线图,这是我用于生成此图的代码和数据集。
ggplot(testdf , aes(measurement, Month)) +
geom_line(aes(group = Month)) +
geom_point(aes(color = Year))
testdf <- structure(list(Month = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8,
9, 10, 11, 12), Year = c(2014, 2014, 2014, 2014, 2014, 2014,
2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014,
2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014,
2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014), measurement = c(0.615151515,
0.59116161625, 0.609090909, 0.613131313, 0.621212121, 0.63964646425,
0.619191919, 0.634343434, 0.645454545, 0.676767677, 0.6368686865,
0.6459595955, 0.656565657, 0.623232323, 0.638383838, 0.6358585855,
0.651515152, 0.6772727275, 0.675757576, 0.666666667, 0.6964646465,
0.704040404, 0.6843434345, 0.673737374, 0.6792929295, 0.63813131275,
0.6641414145, 0.65782828325, 0.6712121215, 0.709090909, 0.7136363635,
0.686868687, 0.708080808, 0.724242424, 0.7015151515, 0.7237373735
)), .Names = c("Month", "Year", "measurement"), row.names = c(NA,
-36L), class = c("grouped_df", "tbl_df", "tbl", "data.frame"), vars = "Month", drop = TRUE, indices = list(
c(0L, 12L, 24L), c(1L, 13L, 25L), c(2L, 14L, 26L), c(3L,
15L, 27L), c(4L, 16L, 28L), c(5L, 17L, 29L), c(6L, 18L, 30L
), c(7L, 19L, 31L), c(8L, 20L, 32L), c(9L, 21L, 33L), c(10L,
22L, 34L), c(11L, 23L, 35L)), group_sizes = c(3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), biggest_group_size = 3L, labels = structure(list(
Month = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)), row.names = c(NA,
-12L), class = "data.frame", vars = "Month", drop = TRUE, .Names = "Month"))
问题是y轴标签。如何更改y轴标签,使其显示标签,如1月1日,2月2日,3月3日而不是2.5,5,7.5等。任何有关如何更改y轴标签的建议都非常感谢。
答案 0 :(得分:2)
使用ggplot2
和lubridate
,您可以执行以下操作:
library(ggplot2)
testdf$Month <- lubridate::month(testdf$Month, label = TRUE)
ggplot(testdf, aes(measurement, Month)) +
geom_line(aes(group = Month)) +
geom_point(aes(color = Year))
如果您不想缩短月份,可以使用lubridate
修改abbr = FALSE
行:
lubridate::month(testdf$Month, label = TRUE, abbr = FALSE)
答案 1 :(得分:0)
第一行基于这里的回答:https://stackoverflow.com/a/39423556/5333994
CASE
WHEN d_outage_min = " " then "blank" else d_outage_min
END
CASE //Error occurred here
WHEN v_outage_min = " " then "blank" else v_outage_min
END
CASE...END