我想在 facet_wrap 生成的圖形上添加不同的注釋。
我嘗試了下面的代碼,但它顯示錯誤,例如“FUN(X [[i]],...)中的錯誤:找不到物件'值'”。
dat_text <- data.frame(
label = c("TRUE:FALSE = 686:324", "TRUE:FALSE = 976:34", "TRUE:FALSE = 516:494", "TRUE:FALSE = 360:650",
"TRUE:FALSE = 351:659", "TRUE:FALSE = 440:570", "TRUE:FALSE = 645:365", "TRUE:FALSE = 151:859", "TRUE:FALSE = 542:468"),
cyl = c(Agricultural_land, Artificial_land, Precipitation, Protected_area,
RiverLake, Seashore, Temperature, Volcanic_area, Wasteland)
)
z_cor <- fit01_zsize2 %>%
ggplot(aes(x = value_without, y = value_with, color = value))
geom_point(shape = 1)
geom_text(
data = dat_text,
mapping = aes(x = -Inf, y = -Inf, label = label),
hjust = -0.1,
vjust = -1
)
geom_abline(intercept = 0, slope = 1, linetype = "dashed")
scale_color_manual(values = c("TRUE" = "salmon", "FALSE" = "steelblue"))
facet_wrap(.~variable1)
theme(strip.text.x = element_text(size = 20),
axis.title=element_text(size=16))
plot(z_cor)
當我嘗試沒有 geom_text() 的相同代碼時,它起作用了。
當我可以避免錯誤時,新的問題來了。我粘貼了我創建的圖形。許多注釋已經出現在一個圖中。

uj5u.com熱心網友回復:
正如@stefan 所指出的,您的文本層的資料應該參考 faceting 變數:
ggplot(mtcars, aes(wt, mpg))
geom_point()
facet_wrap(~am)
geom_text(data = data.frame(wt = 2, mpg = c(30, 12), am = c(0,1),
label = c("one note", "and another")),
aes(label = label))

轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/462729.html
上一篇:更密集的ggplot圖形
