如何在ggplot2中调整X轴标签位置

时间:2013-07-17 17:44:54

标签: r ggplot2

我一直在努力定制ggplot2生成的数字标签。最初,轴是HabFac,只有三个级别。但是,我需要通过HabFac对x轴进行分组,但其标签是其他的。

  1. 因此,我将x轴的限制增加到7。
  2. 使用scale_x_discrete链接新的限制和标签。
  3. 但这不起作用...... enter image description here 看起来标签和盒子的比例是不同的。我试图指定breaks,但它没有帮助。

    非常感谢任何帮助!

    CODE:

    limit_plot=c(levels(data_plot_TT$HabFac), "1", "2", "3", "4")
    break_plot = c(0.75, 1.25, 1.75, 2.00, 2.25, 2.75, 3.25)
    species_label=unique(mlrfrog$Species)
    p_TT=ggplot(data_plot_TT, aes(x= HabFac , y = logTissueConc,  fill = Species)) + geom_boxplot() + scale_x_discrete(limits=limit_plot, labels=letters[1:7])
    

    修改

    以下是一些简化数据

    structure(list(Species = structure(c(1L, 1L, 1L, 1L, 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, 2L, 2L, 2L, 2L), .Label = c("Barking treefrog", 
    "Cricket frog"), class = "factor"), Chemical = structure(c(1L, 
    1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
    3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 1L, 1L, 1L, 1L, 1L, 5L, 5L, 5L, 
    5L, 5L), .Label = c("A", "B", "C", "D", "E"), class = "factor"), 
        logTissueConc = c(-1.10922426, -1.55698525, -0.67977088, 
        -1.22868756, -0.47476868, -0.89399639, -1.35670286, -2.35421158, 
        -2.49491771, -2.30921816, 2.06394108, 1.84732292, 1.62127641, 
        1.7299181, 1.72845824, -0.42136482, -0.03384518, -0.76756916, 
        -0.77322993, -1.20469607, -1.31449937, -1.52823116, -1.94002471, 
        -1.29272381, -1.75399776, -3, -0.5, -0.98828589, -1.2, -0.7, 
        0.73098756, 0.56309363, 0.55666185, 0.3785305, 0.31730552
        ), HabFac = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
        2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
        2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("Aquatic", 
        "Arboreal"), class = "factor")), .Names = c("Species", "Chemical", 
    "logTissueConc", "HabFac"), class = "data.frame", row.names = c(NA, 
    -35L))
    

0 个答案:

没有答案