如何在 2008 年之前為該圖著色作為切點?就像,2008 年之前都共用一種顏色,2008 年之后使用另一種顏色。

uj5u.com熱心網友回復:
你需要一個向量,它是你提供顏色的條形數量的長度。你可以嘗試這樣的事情:
color = ifelse(date < 2008, 'red', 'green')
您必須相應地調整測驗。
然后你為情節提供顏色
ggplot(aes(fill = color))
uj5u.com熱心網友回復:
您需要使用annotatefunction withrect作為 geom 的選項:
# Add rectangles
p annotate(
geom = "rect",
xmin=c(2,4),
xmax=c(3,5),
ymin=c(20,10),
ymax=c(30,20),
alpha=0.2,
color="blue",
fill="blue"
)
見https://www.r-graph-gallery.com/233-add-annotations-on-ggplot2-chart.html
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/334668.html
