【问题标题】:Reading in Year not as continuous but discrete on the x axis在 X 轴上读取年份不是连续的而是离散的
【发布时间】:2021-03-29 20:44:43
【问题描述】:

我在将年份读作 2009.0、2009.5、2010、2010.5、2011 时遇到问题

我尝试将年份更改为字符,但它只是弄乱了线条。

ggplot(allom, aes(x= year, y= acidity, shape= cultivar, color= cultivar)) + 
  geom_line(size=1) +
  geom_point()+
  facet_wrap(vars(location))+
  labs(title = "Apple Acidity(mg/l malic acid) Between Location 1 & 2 ",
       subtitle = "2009-2011 ",
       caption = "source: Provided Data Set",
       y = "Acidity") +
  theme_minimal() +
  scale_color_brewer(palette = "Dark2")

年份带小数的结果图:

【问题讨论】:

    标签: r axis-labels


    【解决方案1】:

    你可以试试df$year <- as.integer(df$year)。但它会删除小数部分。

    【讨论】:

    • ggplot(allom, aes(x= allom$year, y= acidity, shape= cultivar, color= cultivar)) + geom_line(size=1) + geom_point()+ facet_wrap(vars(location ))+ labs(title = “位置 1 和 2 之间的苹果酸度(mg/l 苹果酸)”, subtitle = “2009-2011”, caption = “来源:提供的苹果数据集”, y = “酸度 (mg/ l 苹果酸)") + theme_minimal() + scale_color_brewer(palette = "Dark2")+ xlab('Years')'
    • 警告信息:1:不鼓励使用allom$year。请改用year。 2:不鼓励使用allom$year。请改用year
    • 我是不是把 allom$year 放错地方了?
    • x = as.integer(year)
    • 由于某种原因无法正常工作。在我的岁月里仍然给我小数。
    【解决方案2】:

    我们可以使用

    df$year <- ceiling(df$year)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多