简体   繁体   English

ggplot和facet中的反向Y轴

[英]Reverse Y axis in ggplot and facet

I have a data set contains a depth data from 0 - 140 and other columns include some percentages. 我有一个数据集,其中包含0到140之间的深度数据,其他列中包含一些百分比。 I plot the data using ggplot and facet and it was great except the zero on the y axis (depth) at bottom of the axis. 我使用ggplot和facet绘制数据,除了y轴(深度)的零位于该轴的底部之外,它非常棒。 I want this zero to be at the top of y axis. 我希望这个零在y轴的顶部。

this is the data for example: 这是数据,例如:

log <- structure(list(
  Depth = c(5,10,15,20,25,30,35,40,45,50,55, 60,65, 70,75,80, 85,90, 95,100,105,110,
            115,120,125,130,135,140), 
  mic1 =  c(16.93548387,13.55932203, 6.034482759,33.6, 26.8907563, 51.47928994, 
            24.29906542,16.84210526, 26.14379085, 19.72318339,21.77419355,
            53.33333333,50.56179775,19.07514451,27.63819095, 25.6, 23.56687898, 
            19.04761905, 43.33333333,36.30952381,62.45059289,20.43010753,
            32.23140496,16.4021164,47.48201439,48.73646209,17.44186047, 
            39.04109589),  
  mic2 = c(16.93548387, 13.55932203, 6.034482759,33.6, 26.8907563, 51.47928994, 
           24.29906542,16.84210526, 26.14379085, 19.72318339,21.77419355,
           53.33333333,50.56179775,19.07514451,27.63819095, 25.6, 23.56687898, 
           19.04761905, 43.33333333,36.30952381,62.45059289,20.43010753,
           32.23140496,16.4021164,47.48201439,48.73646209,17.44186047, 
           39.04109589)), 
  .Names = c("Depth", "f1", "f2"), row.names = c(NA, 20L), class = "data.frame")

I am using this code to plot them in bars: 我正在使用此代码将它们绘制在条形图中:

logMelt1 <- melt(log, id.vars="Depth")
logm <- ggplot(logMelt1, aes(x=Depth, y=value)) + geom_bar(stat = 'identity') + 
  coord_flip()  + facet_grid( ~ variable, scale ='free_x')
logm

As you can see the Depth axis start from the bottom: 如您所见,深度轴从底部开始: 在此处输入图片说明

I want to know how I can revers the depth axis so the 0 will start at the top? 我想知道如何反转深度轴,以便0从顶部开始?

Maybe try: 也许尝试:

logm <- ggplot(logMelt1, aes(x=Depth, y=value)) + 
  geom_bar(stat = 'identity') + 
  scale_x_reverse() +
  coord_flip()  + 
  facet_grid( ~ variable, scale ='free_x')

to reverse the axis? 反转轴?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM