【发布时间】:2020-04-08 14:52:59
【问题描述】:
我正在尝试像这样在区域图之外添加文本
我试过了
ggplot(data=df, aes(y=Latitude, x=Longitude)) +
geom_raster(aes(fill=PM10)) +
scale_y_continuous(breaks = c(-10,-5,0,5), labels = c("10S","5S","0","5N"),
expand = c(0,0)) +
scale_x_continuous(breaks =c(100,120,140),labels = c("100E","120E","140E"),
expand = c(0,0)) +
ggtitle(expression("Konsentrasi Aerosol PM"[10])) +
theme(plot.title = element_text(hjust = 0.5)) +
scale_fill_gradientn(parse(text="PM10 (μg/m^3)"),colours=warna) +
geom_path(data = shapefile_df, aes(x = long, y = lat, group = group),
color = 'black', fill= "gray") +
annotate("text", x = 98.5, y=6.6, label = "2020-04-01 12:00 WITA") +
annotate("text", x = 98.5, y=-11.6, label = "Waktu Validasi: 2020-04-01 12:00 WITA")
但我得到了
然后我尝试使用cowplot
kiri_atas <- as.data.frame("2020-04-01 12:00 WITA")
ann <- ggplot(kiri_atas, aes(x = 0, y = 0, label =kiri_atas)) +
geom_text() +
theme_void()
plot_grid(ann, a, ncol = 1, rel_heights = c(.05, 1), align = 'v')
我明白了
我尝试使用gtable
a <- ggplot(data=df, aes(y=Latitude, x=Longitude)) +
geom_raster(aes(fill=PM10)) +
scale_y_continuous(breaks = c(-10,-5,0,5), labels = c("10S","5S","0","5N"),
expand = c(0,0)) +
scale_x_continuous(breaks =c(100,120,140),labels = c("100E","120E","140E"),
expand = c(0,0)) +
ggtitle(expression("Konsentrasi Aerosol PM"[10])) +
theme(plot.title = element_text(hjust = 0.5)) +
scale_fill_gradientn(parse(text="PM10 (μg/m^3)"),colours=warna) +
geom_path(data = shapefile_df, aes(x = long, y = lat, group = group),
color = 'black', fill= "gray")
a = gtable_add_grob(a, grobTree(textGrob("left", x=0, hjust=0),
textGrob("right", x=1, hjust=1)),
t=1, l=4)
grid.draw(a)
什么都没有发生,请帮我解决这个问题,如何在左上角、右上角、左下角、右下角添加第一张图片之类的文字?并让标题居中并加粗?
【问题讨论】: