Graphic with same color lines for factors

Asked

Viewed 85 times

2

I have a date frame (DF) of consumption per animal and per day Below is the data below of only two animals

Animal  Dia Consumo
5       9   2533.96
5       10  2329.06
5       11  2943.79
5       12  3361.62
5       13  2890.82
5       14  2538.98
5       15  2978.81
5       16  3038.76
5       17  3038.76
6       10  2314.82
6       11  2434.75
6       12  2643.99
6       13  2320.58
6       14  2439.56
6       15  2139.6
6       16  2459.54
6       17  2339.59

Want to plot a graph of consumption in function of the day. But I want that for each animal the line is of the same color (gray). I am using the command below, but the chart generates different colors for each animal. I also do not want the legend.

DF$Animal <- factor(DF$Animal)
ggplot(data = DF, aes(x = Dia, y = Consumo, colour= Animal)) +
  geom_line()+theme(legend.position="none")+ scale_size_identity() +
  theme_bw() +
  xlim(c(0, 90)) + 
  ylim(c(0, 3000)) 
  • Tire colour of aes and use geom_line(colour = "grey"). Note: no need to transform DF$Animal <- factor(DF$Animal), the ggplot if possible. (And in this case it is possible.)

1 answer

3

You need to specify each Animal in the group, and specify color in the geom_line:

a <- read.csv2("dados.csv")
library(ggplot2)
ggplot(data = a, aes(x = Dia, y = Consumo, group = Animal)) +
  geom_line(color = "grey") +
  theme_bw() +
  scale_x_continuous(breaks = unique(a$Dia))

inserir a descrição da imagem aqui

Different shades of gray can be found here

Browser other questions tagged

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