![](/img/trans.png)
[英]R - How can I color and label the max and min values points of my scatterplot using ggplot2?
[英]How do I color points using ggplot2 in R?
我試圖繪制兩個變量的圖形,然后使用漸變顏色方案進行視覺強調 - 但是,它一直給我一個黑色散點圖,就好像我沒有輸入命令一樣。
假數據集:
Nature_DR = data.frame(Protect_LGA = runif(100, min=0, max=87.5),
DR_2011_Protect = runif(100, min=3, max=10))
這是我的代碼
ggplot(Nature_DR, aes(x=Protect_LGA, y=DR_2011_Protect)) +
geom_point() +
scale_fill_gradient(low="yellow", high ="green") +
geom_smooth(method = 'loess') +
coord_cartesian(xlim = c(0,87.5), ylim = c(3,10)) +
labs(x="Proportion of LGA that is protected",
y = "Standardised Death Rates in 2011",
title = "Relation between Protected Areas and Death Rates")
您已要求ggplot
將顏色漸變應用於fill
美學,但您尚未指定fill
美學。 此外, geom_point()
不使用fill
美學,它使用color
美學。
因此,例如,您可以使用以下內容通過DR_2011_Protect
為點DR_2011_Protect
,這將使用默認顏色漸變:
ggplot(Nature_DR, aes(x=Protect_LGA, y=DR_2011_Protect, color=DR_2011_Protect)) +
geom_point()
或者通過更改您修改的比例將您的顏色漸變應用於點:
ggplot(Nature_DR, aes(x=Protect_LGA, y=DR_2011_Protect, color=DR_2011_Protect)) +
geom_point() +
scale_color_gradient(low="yellow", high ="green")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.