只是想后的你正在试图做的,看看是否有可能为你工作,以及什么GGPLOT2版本。
我还展示了一个适用于每个方面内多个类的线的示例(取决于您正在进行的分析的复杂程度)。
首先安装GGPLOT2如果你没有它已经:
# install.packages('ggplot2')
library(ggplot2)
这里我使用的是内置的虹膜数据集只设置了一些虚拟数据。我基本上试图模拟有19个不同的数据集。
set.seed(1776)
samples <- list()
num_datasets <- 19
datasets <- list(num_datasets)
# dynamically create some samples
for(i in 1:num_datasets) {
samples[[i]] <- sample(1:nrow(iris), 20)
}
# dynamically assign to many data sets (keep only 2 numeric columns)
for(i in 1:num_datasets) {
datasets[[i]] <- cbind(iris[samples[[i]], c('Petal.Length', 'Petal.Width', 'Species')], dataset_id = i)
# assign(paste0("dataset_", i), iris[samples[[i]], c('Petal.Length', 'Petal.Width')])
}
do.call
是有点棘手,但它需要两个参数,一个函数,参数列表适用于该功能。因此,我在我的datasets
对象(它是数据集列表)中的所有不同数据集上使用rbind()
。
combined_data <- do.call(rbind, datasets)
第一个图是显示数据的一个大散点图。
# all data
ggplot(data=combined_data, aes(x=Petal.Length, y=Petal.Width)) +
geom_point(alpha = 0.2) +
ggtitle("All data")
接下来是19个单独的“方面”的情节都在相同的规模和在同一个图形窗口。面与最佳拟合线
# all data faceted by dataset_id
ggplot(data=combined_data, aes(x=Petal.Length, y=Petal.Width)) +
geom_point(alpha = 0.5) +
ggtitle("All data faceted by dataset") +
facet_wrap(~ dataset_id) +
geom_smooth(method='lm', se = F)
情节最后,数据方面再次绘制的,而是由鸢尾花的品种有色和每个物种都有自己最适合的路线。与类别
内最适合的方面的
# all data faceted by dataset_id
ggplot(data=combined_data, aes(x=Petal.Length, y=Petal.Width, color = Species)) +
geom_point(alpha = 0.5) +
ggtitle("All data faceted by dataset with best fit lines per species") +
facet_wrap(~ dataset_id) +
geom_smooth(method='lm', se = F)
情节我看到你所提到的,你有你自己的预先计算最佳拟合线,但是我觉得这个概念可能让你更接近你需要呢?
干杯!