我使用R的繪圖函數繪製下圖。它是時間轉移的向量'shiftTime'的圖。我有另一個向量'強度'的強度值範圍從〜3到〜9。我想用顏色漸變爲基於這些值的點繪圖。我可以在實際繪製點的值上找到顏色的示例,因此在這種情況下,矢量'shiftTime'的值。只要相應的值在同一個索引上,是否也可以使用不同的向量?根據值的向量,情節中的顏色點會有所不同
34
A
回答
89
下面是使用鹼R圖形的溶液:
#Some sample data
x <- runif(100)
dat <- data.frame(x = x,y = x^2 + 1)
#Create a function to generate a continuous color palette
rbPal <- colorRampPalette(c('red','blue'))
#This adds a column of color values
# based on the y values
dat$Col <- rbPal(10)[as.numeric(cut(dat$y,breaks = 10))]
plot(dat$x,dat$y,pch = 20,col = dat$Col)
16
解決方案使用GGPLOT2:
library(ggplot2)
#Some sample data
x <- sort(runif(100))
dat <- data.frame(x = x,y = x^2 + 1)
# Some external vector for the color scale
col <- sort(rnorm(100))
qplot(x, y, data=dat, colour=col) + scale_colour_gradient(low="red", high="blue")
12
相關問題
- 1. 情節不同顏色的
- 2. 情節不同顏色
- 3. MATLAB情節不同顏色
- 4. 根據輪廓顏色的顏色點
- 5. 不同顏色的graphviz節點
- 6. 根據Pyplot中的對應值,線的顏色不同
- 7. XQuery/XPath:嘗試根據不同節點的值返回節點
- 8. 根據同一個向量中的值更改向量值
- 9. 根據轉向時間列中的不同值更改整個行顏色
- 10. 顏色散點圖根據Y值ggplot
- 11. MATLAB情節不同顏色的不同而改變
- 12. igraph節點顏色根據基因表達值屬性
- 13. XSLT更新節點值根據病情
- 14. 爲不同圖形中的節點分配相同的顏色
- 15. 根據系列的數量使用不同的顏色 - Highcharts
- 16. 只有點擊的div纔會有不同的顏色
- 17. 顏色圖形節點不同
- 18. `搜索`沒有根據角色找到節點上的節點
- 19. 根據條件顯示不同顏色的XSLT變量
- 20. 保持顏色縮放相同的不同情節 - Python
- 21. 在不同顏色的情節中繪製多個fitdist對象?
- 22. 根據所有其他顏色生成顏色列表
- 23. 如何根據值對列進行不同的顏色
- 24. 改變車身報告顏色,根據不同的值表
- 25. 如何根據節點值獲取子節點的數量?
- 26. 顏色節點
- 27. [R情節分配點顏色行名
- 28. 根據值更改顏色
- 29. 根據值更改顏色
- 30. 根據條件設置節點的顏色
這是偉大的!我將如何顯示圖例? – 2015-07-13 22:16:46