0
A
回答
0
ifelse
功能是你在這種情況下的朋友。
sample_data <- mtcars[,1:4]
colors <- ifelse(mtcars$am, "blue", "pink")
plot(sample_data, col = colors)
對於您要三種以上的顏色的情況下,從memisc
包cases
功能將執行類似的功能:
library(memisc)
sample_data <- mtcars[,c(1, 3, 5)]
colors <- cases(
mtcars$cyl == 4 -> "red",
mtcars$cyl == 6 -> "blue",
mtcars$cyl == 8 -> "green"
)
plot(sample_data, col = colors)
但是,您的最強大和最靈活的工具是使用ggplot2
包。這是基於使用ggplot2
變量完成着色的一種方法:
library(ggplot2)
qplot(x = mpg, y = drat, col = factor(cyl), geom = "point", data = mtcars)
學習如何使用ggplot2
包將是一個有價值的長期投資。
相關問題
- 1. 非因變量圖的平滑情節
- 2. 連續因子測試
- 3. 添加abline到augPred情節
- 4. 每節添加多個鏈接變量變量
- 5. 將變量添加到連接資產
- 6. 將變量添加到連接表
- 7. XPath連續多個節點
- 8. 如何將連續分節符添加到XWPFDocument?
- 9. 根據變量複製細胞並添加連續編號
- 10. 添加到變量
- 11. 添加坡多圖情節的子圖中的R
- 12. 用Python添加很多變量到MySQL
- 13. 添加多個變量到PHP數組
- 14. 多個變量添加到data.table
- 15. 創建一個基於「N」連續出現的原始因子水平的新因子/變量
- 16. XSLT連續變量中的多個變量不傳播
- 17. 基於因子變量在R中添加新行
- 18. ggplot:避免在x軸上添加因子變量
- 19. 情節errbar當x因子R
- 20. 如何添加更多變量到這個AJAX帖子...?
- 21. JSTree添加節點到子節點
- 22. combobox插入連續變量
- 23. Gnuplot循環連續變量
- 24. 添加到SQL表中連續的值
- 25. 連續將圖片添加到視頻
- 26. jQuery添加類到連續divs點擊
- 27. 連續添加到數據表
- 28. 在多個連續的因素
- 29. 計算連續出現多少個數值的因子
- 30. 將圖片添加到情節-matplotlib PYTHON
您可以嘗試爲您的調用添加諸如'col = ifelse(kitedata_2 $ sex ==「female」,「red」,「blue」)'。或者提供一個可重複的例子。 – Heroka
您可以隨時在配對功能中使用面板選項。 – dc3