我有這樣的資料
df<- structure(list(team_3_F = c("browingal ", "newyorkish", "site",
"team ", "browingal ", "newyorkish", "site", "team ", "browingal ",
"newyorkish", "site", "team ", "browingal ", "newyorkish", "site",
"team "), variable = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L,
2L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L), .Label = c("No.T", "AAA_BBB_US",
"AAA_CCC_US", "AAA_BBB_CCC_US"), class = "factor"), value = c(12,
4, 6, 22, 0.166666666666667, 0.25, 0, 0.181818181818182, 0.0833333333333333,
1, 0, 0.0909090909090909, 0.0833333333333333, 0.25, 0, 0.0909090909090909
)), row.names = c(NA, -16L), class = "data.frame")
我正在嘗試像這樣繪制它
ggplot(df, aes(x = team_3_F, y = variable))
stat_summary_2d(
aes(z = value, fill = after_stat(value)),
geom = "tile")
geom_text(aes(label=round(value,2)))
guides(fill=guide_legend(title="Percent"))
如何引導圖例僅顯示 , 的趨勢顏色,AAA_BBB_US而不顯示 No.T 的趨勢顏色?AAA_BBB_CCC_USAAA_CCC_US
uj5u.com熱心網友回復:
您可以使用, 更改z內部的映射,將值設定為whenstat_summary_2difelsezNAvariable == 'No.T'
ggplot(df, aes(x = team_3_F, y = variable))
stat_summary_2d(
aes(z = ifelse(variable == 'No.T', NA, value), fill = after_stat(value)),
geom = "tile")
geom_text(aes(label = round(value, 2)))
guides(fill = guide_legend(title = "Percent"))
scale_fill_distiller(palette = "Spectral")
coord_equal()
theme_minimal()
theme(panel.grid = element_blank())

轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/444187.html
