4

这是我的脚本和相关情节:

    library(ggplot2)
    library(reshape)
    df <- structure(list(ID = structure(1:19, .Label = c("2818/22/0834", 
   "2818/22/0851", "2818/22/0853", "2818/22/0886", "B0F", "B12T", 
    "B1T", "B21T", "B22F", "B26T", "B33F", "B4F", "P1", "P21", "P24", 
    "P25", "P27", "P28", "P29"), class = "factor"), K = c(0.089, 
    0.094, 0.096, 0.274, 0.09, 0.312, 0.33, 0.178, 0.05, 0.154, 0.083, 
    0.098, 0.035, 0.084, 0.053, 0.061, 0.043, 0.094, 0.101), Na = c(2.606, 
    3.822, 4.977, 2.522, 15.835, 83.108, 52.041, 41.448, 11.849, 
    40.531, 5.854, 10.151, 3.52, 8.445, 5.273, 7.246, 6.177, 14.813, 
    15.569), Cl = c(3.546, 6.181, 8.422, 3.733, 14.685, 96.911, 65.518, 
    79.01, 10.349, 53.361, 6.12, 10.832, 2.313, 10.312, 5.641, 8.708, 
    6.138, 12.302, 20.078), Mg = c(1.487, 1.773, 1.992, 1.143, 2.991, 
    1.678, 2.23, 3.288, 1.148, 2.428, 3.428, 2.729, 0.777, 2.554, 
    2.374, 4.075, 1.993, 1.881, 3.034), Ca = c(5.529, 6.205, 6.59, 
    4.099, 10.631, 4.564, 6.652, 13.374, 4.332, 10.542, 11.194, 10.053, 
    2.969, 7.73, 8.163, 11.539, 6.166, 5.968, 9.299), SO4 = c(0.663, 
    0.831, 0.607, 0.882, 9.013, 0.896, 0.652, 0.021, 1.446, 0.012, 
    8.832, 6.665, 1.003, 2.575, 3.685, 7.121, 3.64, 5.648, 2.397), 
        HCO3 = c(7.522, 5.498, 6.15, 5.242, 8.582, 4.067, 5.65, 9.364, 
        5.435, 8.068, 9.054, 8.326, 4.805, 7.235, 7.488, 9.234, 6.352, 
        6.98, 8.34)), .Names = c("ID", "K", "Na", "Cl", "Mg", "Ca", 
    "SO4", "HCO3"), class = "data.frame", row.names = c(NA, -19L))

    df_melted<-melt(df, na.rm=T)

    ggplot(df_melted, aes(variable, value, group=ID, color=ID))+
      geom_point(size=2) +
      geom_line() +
      theme(legend.position="none") +
      scale_y_log10(breaks=seq(0, 100, 10))

有没有办法删除情节开头和结尾的空格?我尝试使用 xlim,但问题是 x 变量不是数字变量,因此,类似的东西xlim(c("K", "HCO3"))不起作用。 在此处输入图像描述

4

1 回答 1

6

这是一个离散量表,但您仍然可以使用expand如下参数。输出看起来是否可以接受是另一回事。玩转c(0,0)价值观,直到找到适合的东西。在我看来,使用0.1第二个值会产生更好的情节......

ggplot(df_melted, aes(variable, value, group=ID, color=ID))+
      geom_point(size=2) +
      geom_line() +
      theme(legend.position="none") +
      scale_y_log10(breaks=seq(0, 100, 10)) +
        scale_x_discrete(expand = c(0,0))

截屏

于 2013-09-10T11:49:15.623 回答