ggplot2 を使用してファセット プロットを作成したいと思います。この場合、y 軸の最小制限は固定され (たとえば 0)、最大制限はファセット内のデータによって決定されます ( scales="free_y"
.次のようなものは機能しますが、そのような運はありません:
library(plyr)
library(ggplot2)
#Create the underlying data
l <- gl(2, 10, 20, labels=letters[1:2])
x <- rep(1:10, 2)
y <- c(runif(10), runif(10)*100)
df <- data.frame(l=l, x=x, y=y)
#Create a separate data frame to define axis limits
dfLim <- ddply(df, .(l), function(y) max(y$y))
names(dfLim)[2] <- "yMax"
dfLim$yMin <- 0
#Create a plot that works, but has totally free scales
p <- ggplot(df, aes(x=x, y=y)) + geom_point() + facet_wrap(~l, scales="free_y")
#Add y limits defined by the limits dataframe
p + ylim(dfLim$yMin, dfLim$yMax)
これがエラー ( ) をスローすることは私にとってそれほど驚くべきことではlength(lims) == 2 is not TRUE
ありませんが、この問題を開始するための戦略が思い浮かびません。