color gradient R

Asked

Viewed 1,261 times

5

How do I change the color of the graph gradiently with the years variable, starting from white to intense red.

colourCount = length(unique(tabela.estacao$ano))
getPalette = colorRampPalette(brewer.pal(9,"Reds"))

ggplot(tabela.estacao, aes(x=mes, y=tempMedia, group=as.factor(ano) )) +
geom_smooth(aes(colour = ano)) + ggtitle(est) + scale_fill_manual(name="Min-Max-Range and Mean \nof specific Croptypes",
values=getPalette(colourCount))
scale_x_discrete(limits=c("janeiro", "fevereiro", "março", "abril", "maio", "junho", "julho", "agosto", "setembro", "outubro", "novembro", "dezembro"))
theme(axis.text.x = element_text(angle = 90, hjust = 1))

inserir a descrição da imagem aqui

  • 1

    Brunna, use the command dput(tabela.estacao) and paste the result into your question. This way, your data set will be shared and it will be easier for us to help you. It is not necessary to share everything if it is confidential data: just a minimum amount of data that allows the reproduction of your original code.

  • In this link you can find lots of basic information about options of graphical parameters in R using ggplot2.

1 answer

2

You can add a call to the function scale_colour_continous.

For example:

library(ggplot2)
dados <- data.frame(x = runif(100), y = runif(100), ano = rep(2010:2014, each = 20))
ggplot(dados, aes(x = x, y = y, group = as.factor(ano))) +
  geom_smooth(aes(colour = ano)) +
  scale_colour_continuous(low = "white", high = "red")

Browser other questions tagged

You are not signed in. Login or sign up in order to post.