【问题标题】:ggplot2: Changing which values are annotated on the x-axisggplot2:更改在 x 轴上注释的值
【发布时间】:2013-06-15 13:05:29
【问题描述】:

我的问题肯定是重复的,但我找不到答案。

在 x 轴上,我的图中带有勾号的值是:2.5、5、7.5、10、12.5。 我想修改哪些值有勾号以便查看以下值:2,4,6,8,10,12

为了确保我被充分理解:我不想将我的坐标轴更改为非 carthesian 坐标轴,我只想更改 x 轴上的哪些位置被注释。

我怎样才能做到这一点?

这是我当前的代码:

ggplot(data.and.factors.prov,aes(x=number.of.traits,y=FP,colour=factor(Corr))) +  
    stat_summary(fun.data=mean_cl_normal,position=position_dodge(width=0.2)) + 
    geom_blank() + 
    geom_smooth(method='lm',se=F,formula=y~I(x))  + 
    labs(x='Number of traits') + 
    scale_colour_manual(values=c(1:6),name='Correlation Coefficient') + 
    xlim(c(1,12))

【问题讨论】:

  • 请同时提供您的数据 (data.and.factors.prov)
  • 根据您目前所展示的内容,我猜是scale_x_discrete(breaks=c(2,4,6,8,10,12))
  • 这是一个大数据集,不符合有限字符数的范围。我该怎么办?
  • 发布一个小数据,你可以用它来表达你的观点。
  • 是的,scale_x_discrete 可以满足我的要求!非常感谢 !你想把它写成答案而不是评论吗?

标签: r ggplot2 axes


【解决方案1】:

使用scale_x_discrete(breaks = seq(2, 12, by=2))

【讨论】:

    猜你喜欢
    • 2016-01-16
    • 2015-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-27
    • 1970-01-01
    • 2022-07-12
    相关资源
    最近更新 更多