Home > front end >  Filling up histograms with ggplot - Changing colours
Filling up histograms with ggplot - Changing colours

Time:12-14

I am learning how to use the R and ggplot library and got stucked with the challenge to change the colour of the following Histogram! I did manage to change the full colour from the graph but it was with solid colours! I wanted to get count with different colours and somehow I am not managing to find out the right way to do so! Can you help me to change it to another colour?

df4 <- data.frame(rnorm(10000,100,10))
colnames(df4) <- c("Value")

histi_base2 <- ggplot(df4, aes(x=Value))

histi5 <- histi_base2   geom_histogram(binwidth = 1, colour="blue", alpha=0.8, aes(fill=..count..))   labs(title="My first Histogram", subtitle = "in blue")
histi5

enter image description here

CodePudding user response:

Try:

df4 <- data.frame(rnorm(10000,100,10))
colnames(df4) <- c("Value")

histi_base2 <- ggplot(df4, aes(x=Value))
histi5 <- histi_base2   
  geom_histogram(binwidth = 1, alpha=0.8, fill="red", color="black")   
  labs(title="Your second Histogram", subtitle = "now in solid red")
histi5

With fill you're changing the color inside the bars and with color you're changing the borders. enter image description here

PS: sorry, think I haven't understand it correctly. Martins solution seems to fit better.

  • Related