使用地图功能向我在下面创建的每个ggplot添加标题的最简单方法是什么?我希望标题反映每个数据框的名称 - 即4,6,8(圆柱体)。
谢谢:)
reset
set terminal win
set ticslevel 0
set xlabel 'Length position' rotate parallel offset -2,-1
set ylabel 'Width position' rotate parallel
set zlabel 'Absorbance' rotate parallel
set pm3d
set style fill transparent solid 0.55
set palette color negative
#set view equal xy
set xtics ("1" 0, "2" 1, "3" 2, "4" 3, "5" 4, "6" 5)
set ytics ("1" 0, "2" 1, "3" 2)
set dgrid3d 40,40 splines
splot 'data_file.txt' matrix w l lw 0.6 lc rgbcolor 'black'
set terminal pdf
set output "name_of_output_file.pdf"
replot
答案 0 :(得分:7)
将map2
与names
一起使用。
plots <- map2(
mtcars_split,
names(mtcars_split),
~ggplot(data = .x, mapping = aes(y = mpg, x = wt)) +
geom_jitter() +
ggtitle(.y)
)
编辑:alistaire指出这与imap
plots <- imap(
mtcars_split,
~ggplot(data = .x, mapping = aes(y = mpg, x = wt)) +
geom_jitter() +
ggtitle(.y)
)
答案 1 :(得分:0)
也许您有兴趣使用facet_wrap
代替
ggplot(mtcars, aes(y=mpg, x=wt)) + geom_jitter() + facet_wrap(~cyl)
答案 2 :(得分:0)
您可以使用purrr::map2()
:
mtcars_split <- mtcars %>% split(mtcars$cyl)
plots <- map2(mtcars_split, titles,
~ ggplot(data=.x, aes(mpg,wt)) + geom_jitter() + ggtitle(.y)
)
修改强>
抱歉与保罗回答重复。