R 似乎无法重命名“缩放y/x”图中的标签
我试图重命名y轴上的标签,但似乎无法使其工作R 似乎无法重命名“缩放y/x”图中的标签,r,ggplot2,R,Ggplot2,我试图重命名y轴上的标签,但似乎无法使其工作 ggplot() + geom_point(data = DF, aes(x = -x, y = y, color = color), size = 4) + coord_flip() + scale_y_discrete( #breaks = c(1, 2, 3, 4, 5, 6, 7), labels = c( "1" = "2009", "2" = "2010",
ggplot() +
geom_point(data = DF, aes(x = -x, y = y, color = color),
size = 4) +
coord_flip() +
scale_y_discrete(
#breaks = c(1, 2, 3, 4, 5, 6, 7),
labels = c(
"1" = "2009",
"2" = "2010",
"3" = "2011",
"4" = "2012",
"5" = "2013",
"6" = "2014",
"7" = "2015",
"8" = "1016"
)
)
我想沿着y轴数年,但是比例y\u离散()
似乎找不到正确的标签
当我跑步时:
ggplot() +
geom_point(data = DF, aes(x = -x, y = y, color = color),
size = 4)
我从1-8得到y轴标签。我想把它们改成年
数据:
DF如果将y更改为因子或字符,则离散刻度将起作用
例如:
DF <- structure(list(x = c(1L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 4L,
5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 1L, 2L, 3L, 4L, 5L,
6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L,
4L), y = c(1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5, 1, 2,
3, 4, 5, 6, 2, 3, 4, 5, 6, 7, 3, 4, 5, 6, 7, 8, 4, 5, 6, 7, 5,
6, 7, 6, 7, 7), color = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L,
2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L), .Label = c("black", "blue", "red", "grey"), class = "factor")), class = "data.frame", row.names = c(NA,
-43L))
ggplot() +
geom_point(data = DF, aes(x = -x, y = as.factor(y), color = color),
size = 4) +
coord_flip() +
scale_y_discrete(
#breaks = c(1, 2, 3, 4, 5, 6, 7),
labels = c(
"1" = "2009",
"2" = "2010",
"3" = "2011",
"4" = "2012",
"5" = "2013",
"6" = "2014",
"7" = "2015",
"8" = "1016"
)
)