更改X轴ggplot2上的刻度标签

时间:2019-03-26 14:55:53

标签: r ggplot2

在ggplot2中,我创建了一个折线图,并使其看起来像我想要的样子。但是,我很难更改x轴上的值。如何将x轴刻度标签从数字1-10更改为某些文本?

这是我的代码:

pd <- position_dodge(0.1) 

myplot <- ggplot(LL_young_gg, aes(x=Day, y=Mean, colour=Group)) + 
      geom_errorbar(aes(ymin=Mean-SEM, ymax=Mean+SEM), width=.1, position=pd) +
      geom_line(position=pd) + scale_color_manual(values=c("red", "pink", "dark blue", " light blue")) +
      geom_point(position=pd)

myplot + theme_bw() +
  theme(axis.line = element_line(colour = "black"),
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        panel.border = element_blank(),
        panel.background = element_blank())

数据库(LL_young_gg)是从excel导入的,列(天)的数字是1到10。

1 个答案:

答案 0 :(得分:1)

您可以使用scale_x_continuous()。可重现的示例:

library(ggplot2)

data(mtcars)

xLabels <- paste(c(4,6,8), "Cylinders")

ggplot(mtcars,
       aes(x = cyl,
           y = qsec
           )
       ) +
  geom_point() +
  scale_x_continuous(breaks = c(4,6,8),
                     labels = xLabels
                     )

enter image description here