简体   繁体   English

在ggplot2中使用geom_ribbon反转X轴和Y轴

[英]inverse X and Y axis using geom_ribbon in ggplot2

is it possible to use geom_ribbon from the package ggplot2, but with the range plotted horizontally and not vertically. 是否可以使用包ggplot2中的geom_ribbon,但是范围是水平绘制而不是垂直绘制。 This would be trivial if "geom_ribbon" proposed the options xmin/xmax, but this is not the case. 如果“geom_ribbon”提出选项xmin / xmax,这将是微不足道的,但事实并非如此。

Here is my data, a simplified plotting function for testing and the figure I obtain. 这是我的数据,用于测试的简化绘图功能和我获得的图。 So in this example, I would like to have the "depth" axis displayed vertically. 所以在这个例子中,我希望垂直显示“深度”轴。

prof <- read.table(text = " depth prop mean error
1 5 FALSE 2.12 0.035
2 15 FALSE 2.06 0.035
3 25 FALSE 1.54 0.035
4 35 FALSE 0.92 0.033
5 45 FALSE 0.71 0.028
6 55 FALSE 0.60 0.026
7 65 FALSE 0.54 0.024
8 75 FALSE 0.49 0.023
9 85 FALSE 0.46 0.022
10 95 FALSE 0.43 0.022
11 105 FALSE 0.41 0.022
12 115 FALSE 0.39 0.021
13 5 TRUE 2.18 0.061
14 15 TRUE 2.11 0.061
15 25 TRUE 1.58 0.054
16 35 TRUE 0.97 0.047
17 45 TRUE 0.76 0.042
18 55 TRUE 0.67 0.043
19 65 TRUE 0.61 0.040
20 75 TRUE 0.54 0.033
21 85 TRUE 0.48 0.028
22 95 TRUE 0.45 0.027
23 105 TRUE 0.43 0.025
24 115 TRUE 0.40 0.022", header=TRUE)

ggplot(prof, aes(colour = prop, fill = prop)) + 
  geom_ribbon(aes(x = depth, ymin = mean-error, ymax = mean+error), 
  alpha = 0.6, colour = NA)

在此输入图像描述

Have look at coord_flip() This is untested since you didn't provide the data in an easy format. 看看coord_flip()这是未经测试的,因为你没有以简单的格式提供数据。 Post the output of dput(your.data.frame) to provide data. 发布dput(your.data.frame)的输出以提供数据。

ggplot(prof, aes(x = depth, ymin = mean - error, ymax = mean + error, 
    fill = prop)) + geom_ribbon() + coord_flip()

andpleaseusethelargebaratthebottomofyourkeyboardwhentypingcodewhitespacemakestextmuchmorereadablecodeisalsotext andpleaseusethelargebaratthebottomofyourkeyboardwhentypingcodewhitespacemakestextmuchmorereadablecodeisalsotext

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

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