Reputation: 45
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
Upvotes: 3
Views: 1315
Reputation: 3294
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.
PS: sorry, think I haven't understand it correctly. Martins solution seems to fit better.
Upvotes: 1
Reputation: 16978
You could use scale_fill_gradient
:
df4 <- data.frame(rnorm(10000,100,10))
colnames(df4) <- c("Value")
library(ggplot2)
ggplot(df4, aes(x=Value)) +
geom_histogram(binwidth = 1, alpha=0.8, aes(fill=..count..)) +
scale_fill_gradient(low = "red", high = "green") +
labs(title="My first Histogram")
Upvotes: 4