You're welcome.
I read your data, and find out that the information of Temp. and Rainfall are already shown in x- and y- coordinates. By principle, there's no need to apply them into color again, the information is repeated. But if you insist, try to map your ideal parameters in the aesthetics (i.e., mapping = aes(...)
):
ggplot(data = data_pak,aes(x=Temperature, y=Rainfall)) +
geom_point(mapping = aes(colour = Rainfall))
you'll get
You can see that the color is changing vertically since the Y-axis represents Rainfall.
Geometry aesthetics in any plot should provide additional information than the coordinate. For example, Year
is seemed suitable as the additional information:
colors30 <- colorRampPalette(colors = c("red","yellow","green","blue"))(30)
ggplot(data = data_pak,aes(x=Temperature, y=Rainfall)) +
geom_point(aes(color = as.character(Year))) +
scale_color_manual(values = colors30)
you'll get
Here color shows year of each point.
For anyone new to R and tidyverse syntax, I recommend to read Hadley Wickham(the author of tidyr, dplyr, and ggplot2)'s book R for data science , in chapter 3 He detailedly introduces show to use ggplot to draw a plot.