ggplot(unique(films2[,c("film","word.len.avg")]) ,aes(film,word.len.avg,fill=film,))
geom_bar_pattern(stat="identity",
pattern =
c(
"circle",
"stripe",
"none",
"wave",
"crosshatch"
),
pattern_angle = c(rep(45, ),
rep(60, ),
rep(45, ),
rep(45, ),
rep(45,)),
fill = 'white',
colour = 'black',
pattern_density = .35,
pattern_fill = 'darkblue',
pattern_colour = 'darkblue'
)
scale_x_discrete(breaks = c("dial.m.for.murder", "pscyho", "rear.window", "rope", "vertigo"),
labels = c("Dial M for Murder", "Psycho", "Rear Window", "Rope", "Vertigo"))
theme_bw()
aes(pattern = film)
theme(legend.position = "right")
coord_fixed(ratio = 1.5)
scale_pattern_spacing_discrete(range = c(0.01, 0.05))
嗨,我有上面的代碼,用于帶有圖案填充的條形圖。請參閱下面的相關圖片。這是我在堆疊溢位時從各種來源拼湊而成的代碼,我很高興它終于起作用了,因為我現在終于有了五個條,每個條都有不同的填充模式。但是,很明顯,這些模式不一定與特定電影相關聯(電影有五個值)。我想知道如何將圖案填充映射到特定的電影,因為目前傳奇不會顯示,我假設是因為這個(即事情沒有正確映射?)。任何建議將不勝感激。馬羅
只是補充一下,我在網上找到了這個
你可能已經注意到我使用了geom_col_pattern()
.
我看到你有aes(pattern = film)
這條線沒有做任何事情,它需要系結到一個geom_
或stat_
呼叫。
如果您確定了變數的呈現方式,則可以使用
scale_color_manual
和scale_fill_manual
呼叫來執行此操作。
例如:
ggplot(unique(films2[,c("film","word.len.avg")], aes(film, word.len.avg,, fill = film))
geom_bar_pattern(stat="identity",
pattern = c("circle", "stripe", "none",
"wave", "crosshatch" ),
pattern_angle = c(45, 60, rep(45, 3)),
# fill = 'white',
colour = 'black',
pattern_density = .35,
pattern_fill = 'darkblue',
pattern_colour = 'darkblue'
) scale_fill_manual(values = setNames(c("darkred", "darkblue", "white",
"lightyellow", "gray"),
unlist(df$film)))
scale_x_discrete(breaks = c("dial.m.for.murder", "pscyho",
"rear.window", "rope", "vertigo"),
labels = c("Dial M for Murder", "Psycho", "
Rear Window", "Rope", "Vertigo"))
theme_bw()
# aes(pattern = film)
theme(legend.position = "right") scale_pattern_fill_viridis_c()
coord_fixed(ratio = 1.5)
scale_pattern_spacing_discrete(range = c(0.01, 0.05))
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/469536.html
上一篇:ggplot2scale_color_identity()如何改變線型和圖例的設計?
下一篇:通過R在集群之間繪制直方圖