[英]Add text outside area plot in ggplot2 error
我正在尝试像这样在 plot 区域之外添加文本
我试过了
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)
没有任何反应,请帮我解决这个问题如何在左上角、右上角、左下角、右下角添加第一张图片等文本? 并在中心和粗体中获得标题?
只是一个快速的答案,但您可以尝试为某些文本添加诸如副标题和标题之类的内容。 我从这里得到信息: https://www.datanovia.com/en/blog/ggplot-title-subtitle-and-caption/
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)) +
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") +
labs(title = "title",
subtitle = "subtitle",
caption = "caption")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.