I used the code below but it only shows charts with no color
gbar <- ggplot(data=episode_data, aes(x=season))
gbar +
geom_bar() +
scale_fill_brewer(type = "seq", palette = 1, direction = 1, aesthetics = "fill")
I used the code below but it only shows charts with no color
gbar <- ggplot(data=episode_data, aes(x=season))
gbar +
geom_bar() +
scale_fill_brewer(type = "seq", palette = 1, direction = 1, aesthetics = "fill")
As no data is provided, I will explain you two way to add color in a plot using demo data iris
. You can set the aesthetic element fill
in order to add some variable to fill your bars. The output of a code using that option would be next:
library(ggplot2)
library(tidyverse)
#Data
data("iris")
#Example 1 color by species
iris %>% pivot_longer(-Species) %>%
ggplot(aes(x=name,y=value,fill=Species))+
geom_bar(stat='identity')
Output:
The second option would be directly enable fill
option inside geom_bar()
with some defined color like this:
#Examples 2 only one color
iris %>% pivot_longer(-Species) %>%
ggplot(aes(x=name,y=value))+
geom_bar(stat='identity',fill='cyan3')
Output:
For the code you added try this, and next time please include a sample of your data to reproduce your issue:
#Option 1
ggplot(data=episode_data, aes(x=season))+
geom_bar(stat='identity',fill='red')
#Option 2
ggplot(data=episode_data, aes(x=season,fill=factor(season)))+
geom_bar(stat='identity')