在以下對facet_wrap的使用中,年份和模型都被顯示在繪圖示簽中。
library(tidyverse)
mpg%>%
filter(manufacturer=='audi')%>%
ggplot(Aes(cty, hwy))
geom_point(aes(col =) operator">= model))
facet_wrap(year~model)
我們已經通過model對點進行了著色,并且在圖例中顯示了它,所以我們并不真的需要在每個面的標簽中使用model。我們怎樣才能從標簽中洗掉model呢?
uj5u.com熱心網友回復:
最簡單的方法是調整labeler函式,只提取第一個變數的標簽。你可以用
來做到這一點mpg %>%
filter(manufacturer=='audi')%>%
ggplot(Aes(cty, hwy))
geom_point(aes(col =) operator">= model))
facet_wrap(~年 模。 labeller=function(x) {x[1]})
另一種方法是創建一個互動變數,這樣你就只對一個變數進行切面處理,然后你可以改變標簽,將第二個值的名稱剝離出來。這看起來就像這樣
mpg %>%
filter(manufacturer=='audi')%>%
ggplot(Aes(cty, hwy))
geom_point(aes(col =) operator">= model))
facet_wrap(~interaction(year, 模型)。 labeller=as_labeller(function(x)gsub("。 . *$", "。 x)))
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/330220.html
標籤:


