我试图ggplot2在y轴显示标签的位置制作切面图,x轴应显示两个不同尺度(在不同尺度上)的每个标签的值的折线图.到目前为止我有这个:
Data <- structure(list(label = structure(
c(1L, 1L, 2L, 2L, 3L, 3L, 4L,
4L, 5L, 5L, 6L, 6L), .Label = c("A", "B", "C", "D", "E", "F"), class = "factor"),
facet = structure(c(1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L,
1L, 2L), .Label = c("A", "B"), class = "factor"), value = c(0.0108889081049711,
0.37984336540103, 0.0232500876998529, 0.777756493305787,
0.0552913920022547, 0.920194681268185, 0.0370863009011373,
0.114463779143989, 0.00536034172400832, 0.469208759721369,
0.0412159096915275, 0.587875489378348), group = c(1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1)), …Run Code Online (Sandbox Code Playgroud) 我试图在带有刻面的Boxplot图像上有自由比例.
使用此示例数据集,如果我尝试这样做:
ggplot(data=mpg) +
geom_boxplot(aes(x=cty, y=model))+
facet_grid(manufacturer ~ drv, scales = "free", space = "free")
Run Code Online (Sandbox Code Playgroud)
绘制不正确的箱图http://dl.dropbox.com/u/9788680/plot1.png
在这里,自由尺度完全按照我的意愿实现,y轴的不同尺度取决于水平面规则的可用因子的数量.然而,箱图未被正确描绘(即,实线而不是箱线图).在搜索解决方案时,我发现我应该使用coord_flip()以便正确描绘箱形图,即
ggplot(data=mpg) +
geom_boxplot(aes(x=model,y=cty))+
facet_grid(manufacturer ~ drv, scales = "free", space = "free")+
coord_flip()
Run Code Online (Sandbox Code Playgroud)
绘制正确的boxplot,但没有缩放http://dl.dropbox.com/u/9788680/plot2.png
在上图中,箱图现在是正确的.但是,去除了因子(因此在y轴上)的自由标度.现在,对于每个水平构面线,现在包括数据集中的所有可用因子,而不是仅包含每个构面可用的因子(如图1所示).
我想知道如何通过两个轴上的自由刻度获得正确的刻面,正确描绘了箱线图.
如果有人能指出我正确的方向,我将不胜感激.
谢谢.