簡體   English   中英

使用grid.raster()繪制后如何添加顏色的強度圖例?

[英]How do I add intensity legend of colors after I plot using grid.raster()?

在此處輸入圖片說明 我正在對png圖像進行kmeans聚類,並已使用grid :: grid.raster(image)對其進行了繪制。 但我想在圖例上放置一個圖例,以強度值(從藍色到紅色)標記值,從本質上指示圖像上的強度。 (圖像是第三個維度等於3的數組,給出了紅色,綠色和藍色通道。)我想過使用grid.legend(),但無法弄清楚。 我希望社區能夠幫助我。 以下是我一直使用的圖像,在執行kmeans聚類后,想要在其旁邊有一個圖例,該圖例在色條上連續顯示強度。 我也嘗試了ggplot2,可以繪制圖像,但仍然無法繪制圖例。 我正在提供用於繪制圖像的ggplot代碼。 我也可以使用ggplot2分別提取RGB通道,因此顯示它也很有幫助。

colassign <- rgb(Kmeans2@centers[clusters(Kmeans2),])
library(ggplot2)
ggplot(data = imgVEC, aes(x = x, y = y)) + 
  geom_point(colour = colassign) +
  labs(title = paste("k-Means Clustering of", kClusters, "Colours")) +
  xlab("x") +
  ylab("y")

找不到適當使用grid.raster()的方法,但是找到了分別繪制RGB通道時通過ggplot2進行處理的方法。 注意:這僅適用於單獨繪制面板,但這是我需要的。 以下顯示綠色通道的代碼。

#RGB channels are respectively stored in columns 1,2,3.
#x-axis and y-axis values are stored in columns 4,5.
#original image is a nx5 matrix
ggplot(original_img[,c(3,4,5)], aes(x, y)) +
  geom_point(aes(colour = segmented_img[,3])) +
  scale_color_gradient2()+ 
# scale_color_distiller(palette="RdYlBu") can be used instead of scale_color_gradient2() to get color selections of choice using palette as argument.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM