r-ggplot:Y轴刻度重叠

时间:2018-04-12 16:36:30

标签: r ggplot2 graph facet

问题在于:我正在尝试使用ggplot和facet_wrap绘制销售数据;但是,y轴上的比例是重叠的。所以,我尝试使用 scale_y_discrete 并使用 中断 来修复它,但似乎不准确! 有人可以帮我解决这个问题吗?

P.S:我对R和Stackoverflow都很新,希望我正确地遵循指南提出问题!

以下是我的代码:

p <- ggplot(melt(GrossRev_Mnthly, id.vars=c("Month","Sales")), 
            aes(x = Month, y = value, group = Sales, color = Sales)) + 
  geom_line(size = 1) + 
  scale_x_discrete(labels = c("January"="Jan", "February"="Feb", "March"="Mar", 
                              "April"="Apr", "June"="Jun", "July"="Jul", "August"="Aug", 
                              "September"="Sep", "October"="Oct", "November"="Nov", 
                              "December"="Dec")) + 
  facet_wrap(~variable, scales = 'free_y')

p+scale_y_discrete(breaks = seq(0, 1000, by=100))

以下是我的数据框的尾部(24):

structure(list(Month = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L,8L, 9L, 10L, 
11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L), .Label = 
c("January", "February", "March", "April", 
"May", "June", "July", "August", "September", "October", "November", 
"December"), class = "factor"), `North America` = c(30310, 39530, 
41870, 45150, 48330, 51150, 45160, 38970, 32630, 29660, 26150, 
23630, 294318.842921784, 384558.72762734, 406611.767189296, 
432626.777058419,462227.655524398, 485614.555256065, 435224.637726637, 
374164.130572544,313966.373102992, 284206.301762252, 252910.383496192, 
228423.055480594), `South America` = c(1150, 1260, 1350, 1540, 1770, 1680, 
1550,1470, 1380, 1340, 1280, 1170, 2804.54086506681, 3006.79875679876, 
3221.54828127229, 3768.33610512905, 4283.8299558342, 4119.46614133315, 
3793.27221909092, 3528.54360004872, 3224.9723145072, 3123.80357969356, 
2955.06429116269, 2720.26172201782), Europe = c(2860, 4350, 5830, 
7490, 7280, 7220, 7300, 7240, 7050, 5610, 4150, 2560, 52948.8237129747, 
78212.3680413154, 105160.124340346, 134577.240556054, 129995.939392091, 
132308.509679254, 133460.627142569, 133512.445887446, 131669.560099194, 
106958.434894841, 79103.1468531469, 49296.0755206387), Pacific = c(800, 
800, 820, 870, 810, 840, 880, 870, 900, 900, 930, 930, 7736.37723601836, 
7615.91124537093, 7779.28852343473, 8271.66428095236, 7692.29075477023, 
7955.62896635154, 8346.35471651516, 8116.88311688312, 8377.30941853963, 
8411.15211095305, 8700.06736026154, 8690.72767388838), China = c("0", 
"0", "0", "5", "16", "22", "26", "14", "15", "11", "3", "1", 
"NA", "NA", "NA", "NA", "NA", "NA", "NA", "NA", "NA", "NA", "NA", 
"NA"), World = c(35120, 45940, 49870, 55055, 58206, 60912, 54916, 
48564, 41975, 37521, 32513, 28291, 357763.584735844, 473393.805670825, 
522772.728334348, 579244.018000554, 604199.715627093, 629998.160043004, 
580824.891804812, 519320.310869229, 457238.214935232, 402699.692347739, 
343668.662000763, 289126.287063806), Sales = c("Mower Unit", 
"Mower Unit", "Mower Unit", "Mower Unit", "Mower Unit", "Mower Unit", 
"Mower Unit", "Mower Unit", "Mower Unit", "Mower Unit", "Mower Unit", 
"Mower Unit", "Mower Total", "Mower Total", "Mower Total", "Mower Total", 
"Mower Total", "Mower Total", "Mower Total", "Mower Total", "Mower Total", 
"Mower Total", "Mower Total", "Mower Total")), .Names = c("Month", 
"North America", "South America", "Europe", "Pacific", "China", 
"World", "Sales"), row.names = 25:48, class = "data.frame")

0 个答案:

没有答案