Есть ли простой способ указать соотношение площадей граней? - PullRequest
0 голосов
/ 14 октября 2019

У меня есть эти данные

structure(list(mz = c(535.013293, 535.113496, 535.213713, 535.314112, 
535.41428, 535.514564, 536.014843, 536.11414, 536.214346, 536.314609, 
536.414881, 536.515069, 536.61525, 536.715443, 536.815648, 536.915817, 
537.016285, 537.316633, 537.414672, 537.515621, 537.615837, 537.71616, 
537.8164, 537.91658, 538.016789, 538.117041, 538.217328, 538.317528, 
538.417798, 538.517666, 538.815937, 538.916182, 539.017179, 539.117423, 
539.217713, 539.317994, 539.418095, 539.518411, 539.618521, 539.718781, 
539.818955, 539.918939, 540.117936, 540.205678, 540.217484, 540.317157, 
540.418649, 540.51902, 540.619159, 540.719454, 540.819572, 540.919687, 
541.019973, 541.120031, 541.220124, 541.320152, 541.420665, 541.617909, 
541.718257, 541.819759, 541.920072, 542.020214, 542.120353, 542.220499, 
542.320682, 542.420886, 542.521056, 542.621181, 542.721435, 542.821594, 
542.909273, 543.00964, 543.109956, 543.119367, 543.220519, 543.320813, 
543.420933, 543.521146, 543.621259, 543.721421, 543.821563, 543.921742, 
544.02194, 544.122233, 544.22174, 544.320211, 544.417956, 544.518764, 
544.620599, 544.720922, 544.821111, 544.921328, 545.021549, 545.121681, 
545.221896, 545.321998, 545.422121, 545.522504, 545.621979, 545.919489, 
546.020348, 546.12054, 546.220863, 546.320986, 546.42127, 546.521437, 
546.62165, 546.649311, 546.721868, 546.822078, 546.922278, 546.98353, 
547.022996, 547.11392, 547.215095, 547.317116, 547.420726, 547.521064, 
547.621291, 547.721545, 547.821649, 547.921848, 548.021987, 548.122254, 
548.222589, 548.322794, 548.422661, 548.515578, 548.615922, 548.716568, 
548.821185, 548.921632, 549.021884, 549.122044, 549.222232, 549.32235, 
549.422586, 549.499768, 549.522754, 549.590471, 549.622949, 549.72286, 
549.823565, 549.917076, 550.017281, 550.117527, 550.221755, 550.322219, 
550.422511, 550.522664, 550.62273, 550.682891, 550.722907, 550.773621, 
550.823113, 550.864566, 550.923219, 551.023299, 551.123265, 551.322231, 
551.418551, 551.518444, 551.622215, 551.723037, 551.823242, 551.92328, 
552.02341, 552.123488, 552.223755, 552.323662, 552.423899, 552.524342, 
552.720164, 552.819564, 552.919665, 553.022332, 553.123126, 553.223509, 
553.323611, 553.423797, 553.523967, 553.624093, 553.658745, 553.724232, 
553.82502, 553.924606, 554.217545, 554.316334, 554.422681, 554.523682, 
554.623881, 554.650425, 554.723979, 554.824086, 554.92424, 554.984601, 
555.024307, 555.124463, 555.224662, 555.325354, 555.772426, 555.825005, 
555.924771, 555.994827, 556.024953, 556.124971, 556.161932, 556.225194, 
556.325107, 556.394844, 556.425057, 556.525112, 556.625267, 556.6844, 
556.984252, 541.718257, 541.819759, 541.920072, 542.020214, 542.120353, 
542.220499, 542.320682, 542.420886, 542.521056, 542.621181), 
    intensity = c(4101L, 3843L, 2935L, 2034L, 853L, 366L, 255L, 
    502L, 1934L, 3808L, 5201L, 5209L, 3984L, 2533L, 1395L, 566L, 
    225L, 510L, 323L, 609L, 4025L, 9803L, 14126L, 13753L, 10928L, 
    6886L, 3680L, 1936L, 588L, 197L, 358L, 727L, 6523L, 17365L, 
    25665L, 26273L, 20401L, 13149L, 7231L, 3447L, 1542L, 422L, 
    180L, 234L, 357L, 1151L, 9874L, 27723L, 40980L, 42641L, 34017L, 
    22099L, 12388L, 6243L, 2700L, 1115L, 253L, 319L, 643L, 10744L, 
    31069L, 47572L, 50223L, 39992L, 27114L, 15050L, 7571L, 3371L, 
    1499L, 375L, 510L, 983L, 854L, 315L, 8313L, 24504L, 37950L, 
    41132L, 34176L, 23337L, 13607L, 7089L, 3190L, 1327L, 416L, 
    187L, 207L, 477L, 7437L, 21624L, 34306L, 36808L, 30248L, 
    20386L, 11983L, 6141L, 2897L, 1205L, 319L, 270L, 7067L, 20839L, 
    32821L, 35644L, 29995L, 20612L, 11978L, 290L, 6361L, 2779L, 
    1170L, 258L, 264L, 192L, 291L, 519L, 5576L, 16571L, 26609L, 
    29283L, 25048L, 17304L, 10274L, 5454L, 2609L, 1056L, 259L, 
    184L, 371L, 508L, 5077L, 14822L, 23171L, 25401L, 21375L, 
    15026L, 8905L, 235L, 4559L, 192L, 2177L, 871L, 222L, 307L, 
    638L, 718L, 4060L, 12007L, 18736L, 20589L, 17893L, 207L, 
    12785L, 260L, 7774L, 220L, 4026L, 1957L, 815L, 339L, 537L, 
    612L, 2350L, 6828L, 10917L, 12912L, 11344L, 8677L, 5526L, 
    3163L, 1489L, 545L, 206L, 498L, 458L, 1735L, 4412L, 6934L, 
    8248L, 7504L, 5725L, 3678L, 243L, 2050L, 1311L, 375L, 312L, 
    1355L, 1167L, 3279L, 5506L, 1066L, 6262L, 5610L, 4134L, 482L, 
    2691L, 1497L, 681L, 324L, 249L, 712L, 1808L, 583L, 3051L, 
    3639L, 237L, 3463L, 2789L, 243L, 1873L, 1053L, 476L, 1597L, 
    194L, 643L, 10744L, 31069L, 47572L, 50223L, 39992L, 27114L, 
    15050L, 7571L, 3371L), range = c("all", "all", "all", "all", 
    "all", "all", "all", "all", "all", "all", "all", "all", "all", 
    "all", "all", "all", "all", "all", "all", "all", "all", "all", 
    "all", "all", "all", "all", "all", "all", "all", "all", "all", 
    "all", "all", "all", "all", "all", "all", "all", "all", "all", 
    "all", "all", "all", "all", "all", "all", "all", "all", "all", 
    "all", "all", "all", "all", "all", "all", "all", "all", "all", 
    "all", "all", "all", "all", "all", "all", "all", "all", "all", 
    "all", "all", "all", "all", "all", "all", "all", "all", "all", 
    "all", "all", "all", "all", "all", "all", "all", "all", "all", 
    "all", "all", "all", "all", "all", "all", "all", "all", "all", 
    "all", "all", "all", "all", "all", "all", "all", "all", "all", 
    "all", "all", "all", "all", "all", "all", "all", "all", "all", 
    "all", "all", "all", "all", "all", "all", "all", "all", "all", 
    "all", "all", "all", "all", "all", "all", "all", "all", "all", 
    "all", "all", "all", "all", "all", "all", "all", "all", "all", 
    "all", "all", "all", "all", "all", "all", "all", "all", "all", 
    "all", "all", "all", "all", "all", "all", "all", "all", "all", 
    "all", "all", "all", "all", "all", "all", "all", "all", "all", 
    "all", "all", "all", "all", "all", "all", "all", "all", "all", 
    "all", "all", "all", "all", "all", "all", "all", "all", "all", 
    "all", "all", "all", "all", "all", "all", "all", "all", "all", 
    "all", "all", "all", "all", "all", "all", "all", "all", "all", 
    "all", "all", "all", "all", "all", "all", "all", "all", "all", 
    "all", "all", "all", "all", "one", "one", "one", "one", "one", 
    "one", "one", "one", "one", "one")), row.names = c(NA, -225L
), class = "data.frame")

Я хотел бы построить все данные в диапазоне и затем увеличить отдельный сегмент.

ggplot(spectrum10plus, aes (x = mz, xend=mz, y=0, yend= intensity)) + geom_segment() + 
  facet_grid(~range, scale = "free_x")

Это дает график, который выглядитвот так

enter image description here

Мне бы хотелось, чтобы соотношение ширины для левой и правой граней стало 3: 1, чтобы левая грань была в три раза шире. Есть ли простой способ указать это?

Ответы [ 2 ]

1 голос
/ 14 октября 2019

Один из способов сделать это, как показано ниже:

    p1 <- ggplot(subset(spectrum10plus,range=="all"), 
             aes (x = mz, xend=mz, y=0, yend= intensity)) + geom_segment()
    p2 <- ggplot(subset(spectrum10plus,range=="one"), 
             aes (x = mz, xend=mz, y=0, yend= intensity)) + 
             geom_segment() + 
             theme(axis.title.y=element_blank(),
             axis.text.y=element_blank())
    grid.arrange(p1, p2, widths = c(1, 0.33), ncol=2)

Или, если вы хотите сохранить фактические коэффициенты, используя facet_grid, как показано ниже:

ggplot(spectrum10plus, aes (x = mz, xend=mz, y=0, yend= intensity)) + geom_segment() + 
  facet_grid(~range, scale = "free_x", space="free")
0 голосов
/ 14 октября 2019

Хотя в ответе Маджида нет ничего плохого, есть альтернатива, использующая gtables для указания ширины:

# Make plot as per usual
g <- ggplot(spectrum10plus, aes (x = mz, xend=mz, y=0, yend= intensity)) + geom_segment() + 
  facet_grid(~range, scale = "free_x")

library(grid)

# Convert to gtable
gt <- ggplotGrob(g)

# Set widths of panels
gt$widths[panel_cols(gt)$l] <- unit(c(1, 1/3), "null")

# Plot
grid.newpage(); grid.draw(gt)

enter image description here

Обратите внимание, что 'Нулевые единицы являются относительными в зависимости от размера графика.

...