【发布时间】:2020-07-08 14:57:44
【问题描述】:
编辑:
我确实找到了一种方法来做我需要的事情,但现在我无法为每个创建的图显示标题,因此我知道我正在查看哪个网站:
lapply(seq(gl), function(i){
lapply(seq(gl[[i]]), function(j){
ggplot() +
geom_point(data = gl[[i]][[j]], aes(x = `UTC_date.1`, y = `actSWE_mm`, color = `swe_Res_mm`))+
geom_segment(data = gl[[i]][[j]], aes(x = `UTC_date.1`, y = `actSWE_mm`, xend = `UTC_date.1`, yend = `swe_mm`), alpha=.2)+
scale_color_steps2(low = "blue", mid = "white", high = "red") +
guides(color = FALSE) + geom_point(data = gl[[i]][[j]], aes(x = `UTC_date.1`, y = `swe_mm`), shape = 1) +
facet_wrap(vars(year), scales="free_x") + theme_bw()
})})
我尝试添加:
主题(plot.title = paste(names(gl)[i], names(gl[[i]])[j], sep = "_"))
但这似乎不起作用。
原文:
我有一个代表每个月的 12 个数据框的列表。在每个数据框中都有几个不同站点的时间序列测量值。下面是一月份数据的表格示例(不是实际数据)(monthSplit 是列表 - monthSplit$January):
site_id UTC_date.1 swe_mm actSWE_mm swe_Res_mm Month Year
<int> <date> <dbl> <dbl> <dbl> <chr> <num>
1003 2005-01-01 2 54.2 0.241 53.059 "January" 2005
1003 2005-01-02 2 54.2 0.241 53.059 "January" 2005
958 2005-01-01 2 154.2 0.241 153.059 "January" 2005
946 2005-01-01 2 154.2 152.25 1.95 "January" 2005
946 2005-01-02 2 500.2 550.241 50.059 "January" 2005
我在尝试对需要被唯一站点进一步子集的数据框列表执行 ggplot 时遇到两个问题。
我尝试创建一个ggplot函数并使用mapply:
plot_fun = function(d) {
ggplot(d, aes(x = `UTC_date.1`, y = `actSWE_mm`)) +
geom_segment(aes(xend = `UTC_date.1`, yend = `swe_mm`), alpha=.2) + geom_point(aes(color = `swe_Res_mm`)) +
scale_color_steps2(low = "blue", mid = "white", high = "red") +
guides(color = FALSE) + geom_point(aes(y = `swe_mm`), shape = 1) +
facet_wrap(vars(year), scales="free_x") + theme_bw()
}
pltlist = mapply(plot_fun, d = monthSplit, SIMPLIFY=FALSE)
这产生了正确格式的绘图和所有内容,但是它没有被 site_id 分割。因此,它创建了一个包含多个图的图,其中包含每年当月的图值。 EG:九月图在一个窗口中产生了 13 个图,代表 2003-2015 年 9 月的每一年。问题是,所有的网站都集中在那里。
在查看实际数据时(如上述绘图函数的情况),由于数据范围在 y 轴上变化如此之大,因此无法从绘图中获得任何意义。
我想知道如何通过 site_id 进一步拆分地块列表,以便每个地块中只出现一个站点以进行比较。
【问题讨论】:
-
您能否提供一个可重现的最小示例来说明您遇到的问题。您可能不需要在实际案例中包含大量数据来解决问题的关键;看看minimal reproducible example 或speakerdeck.com/jennybc/reprex-help-me-help-you?slide=5
-
我进行了编辑以显示问题,或者我的知识差距。