简体   繁体   English

使用facet_grid选项使用ggplot2绘制数据框的列

[英]Use facet_grid option to plot column of dataframe with ggplot2

I get some result from simulation, and i want to make a facetting like this diagram below, and i don't know if it's possible to make this with ggplot2 and the facet_grid option. 我从模拟中得到了一些结果,我想在下面的图中做出一个方面,我不知道是否可以使用ggplot2和facet_grid选项来实现这一点。

My result for simulations have this "simplified" form, one line by simulation : 我的模拟结果有这种“简化”形式,模拟一行:

dat <- read.table(textConnection("P1 P2 P3 P4 R 
1 2e-5 1.0 0.6 3 1
2 4e-6 1.5 0.7 1.5 2
3 6e-7 1.2 0.6 2.5 3 
4 8e-8 1.45  0.65 3.2 4
"))

And here you can see the simplified graphic i want to produce with ggplot2 and facet_grid 在这里你可以看到我想用ggplot2和facet_grid生成的简化图形

图形图像ggplot2

I have one facet/graph by parameter, with different scale corresponding to min/max values for each of my parameter... You can also see on this graphic the color correspondance to localize each simulation in parameter space. 我有一个facet / graph by参数,不同的比例对应于我的每个参数的最小值/最大值...您还可以在此图形上看到颜色对应以在参数空间中本地化每个模拟。

Thanks a lot for help 非常感谢您的帮助

SR. SR。

Here is a start: 这是一个开始:

library(plyr)
library(ggplot2)
dat.melt <- melt(data, id.vars='R')

ggplot(dat.melt, aes(x=0, y=value)) +
    geom_boxplot() +
    geom_point(aes(colour=factor(R))) +
    facet_wrap(~variable, ncol=1, scales='free') +
    coord_flip()

Plenty of other tweaks, but the gist is there. 还有很多其他的调整,但要点就在那里。 Usually a good first step is to melt the data long and then start fiddling. 通常,良好的第一步是长时间melt数据然后开始摆弄。 As a side note, its a good idea to avoid using data for a variable name since its a built in function. 作为旁注,最好避免使用data作为变量名,因为它是内置函数。

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

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