I am not indifferent to colors in ggplot. I am trying to apply a color gradient based on the ranks column below. I am sure that this is a mismatch between color and fill or discrete and continuous variables. I want colors, as shown on the scale in “c” and “d” below, but my closest attempts are “e” and “f”, where the dots are colored but not colored with a gradient. The gradient that I prefer relates to values of rank 1: 100, while all other values are black.
Any help would be most appreciated.
library(reshape2)
library(ggplot2)
co2 <- read.table(
header=TRUE, text='
rank tons
1 2 1.00
2 4 1.00
3 7 0.00
4 44 0.00
5 104 0.00
6 48 0.05
7 32 0.50
8 5 0.00
9 78 1.00
10 12 0.00
11 15 0.00
12 176 1.00
13 440 0.02
14 249 0.00
15 481 0.00
16 388 0.00
17 458 0.05
18 488 0.00
19 264 0.00
20 203 0.00
')
I tried:
c<- ggplot(data=co2, aes(x = tons, color=rank))
c + geom_dotplot(stackgroups = TRUE, binwidth = .05, binpositions = "all") +
scale_colour_gradient(limits=c(1, 500))
d<- ggplot(data=co2, aes(x = tons, color=rank))
d + geom_dotplot(stackgroups = TRUE, binwidth = 0.05, method = "histodot") +
scale_colour_gradient(limits=c(1, 100))
co2$brks<- cut(co2$rank, c(seq(0, 100, 20), max(co2$rank)))
e<- ggplot(data=co2, aes(x = tons, fill=brks))
e + geom_dotplot(stackgroups = TRUE, binwidth = 0.05, method = "histodot")
f<- ggplot(data=co2, aes(x = tons, fill=brks)) + geom_histogram()
f
I checked them already, but I still missed something: