我希望在x轴上有来自列表dates的自定义值,其中包含字符串格式的日期。我对将数据与mpg合并不太感兴趣,因为主列有一个数据结构,其中的值是整数,而我不能在那里有Po-6 is日期。
Vars variable value
1: 1 Leo 164
...图1中当前输出的代码。
library('ggplot2')
str(mpg)
dates <- c("1.1.2017", "1.2.2017", "1.3.2017", "2.4.2017", "10.5.2017", "12.5.2017", "13.5.2017")
# TODO how to have here custom values on x-axis from dates?
ggplot(mpg, aes(x = class, y = hwy)) +
geom_boxplot()您不能简单地拥有x = dates,因为dates不属于mpg。
图1默认x标签的当前输出

预期输出:这7个日期在x轴上的数字.
R: 3.4.0 (backports)
操作系统: Debian 8.7
发布于 2017-05-24 16:36:35
试试这个:
ggplot(mpg, aes(x = class, y = hwy)) +
geom_boxplot() +
scale_x_discrete(labels = dates)如果要在轴中维护值,请使用scale_x_continuous,以便执行以下操作,从而保留y-轴的勾号值
scale_y_continuous("Y Axis Title")https://stackoverflow.com/questions/44164013
复制相似问题