[英]GGPlot won't display more than 3 colors
GGPlot 僅顯示前三個 colors(綠色、黃色和橙色),代碼如下:
p = ggplot(MobileOutput, aes(x=`Timestamp(UTC)`,y=`PM2.5(ug/m3)`))+
geom_point(aes(colour = cut(`PM2.5(ug/m3)`, c(0, 12.0, 35.4, 55.4, 150.4, 250.4, 500, Inf))),
size = 0.1) +
ylim(0,500) +
theme_bw() +
scale_color_manual(name = "PM2.5",
values = c("(0,12]" = "green2",
"(12,35.4]" = "yellow2",
"(35.4,55.4]" = "orange",
"(55.4,150.4]" = "red1",
"(150.4, 250.4]" = "red2",
"(250.4, 500]" = "red3",
"(500, Inf]" = "red4"))
gPlotly <- ggplotly()
所有紅色仍以不可見的清晰/白色繪制。 我能夠對不可見數據進行 hover 並查看其上的信息,確認它正在被繪制(見下圖)。 此外,圖例中它們的范圍旁邊出現了一個綠色、黃色和橙色的點,而圖例中沒有預期的紅點。
如果我調整上面的代碼以包括如下 3 個范圍,則所有 colors 都會按預期顯示:
p = ggplot(MobileOutput, aes(x=`Timestamp(UTC)`,y=`PM2.5(ug/m3)`))+
geom_point(aes(colour = cut(`PM2.5(ug/m3)`, c(0, 12.0, 35.4, Inf))),
size = 0.1) +
ylim(0,500) +
theme_bw() +
scale_color_manual(name = "PM2.5",
values = c("(0,12]" = "green2",
"(12,35.4]" = "yellow2",
"(35.4,Inf]" = "red4"))
gPlotly <- ggplotly()
如果我添加一個額外的范圍,則超出所列第三項的任何內容都會再次完全不可見,如第一張圖片所示。
有沒有我可以調整的東西來讓 GGPlot 支持在圖例和 plot 中顯示超過 3 種顏色/范圍?
它看起來像cut()
舍入其標簽中的值:在此示例中,斷點都位於 (x+0.4),但較大 bin 的端點在標簽中以整數形式給出(150、250 而不是 150.4、250.4) . 這將導致您切割的PM2.5
矢量中的唯一值/水平與您在比例中指定的值/水平不匹配。
table(cut(rnorm(1000,150,200),
breaks=c(0, 12.0, 35.4, 55.4, 150.4, 250.4, 500, Inf)))
(0,12] (12,35.4] (35.4,55.4] (55.4,150] (150,250] (250,500]
17 31 25 194 199 282
(500,Inf]
43
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.