'Adding title and subheadings to histogram in r keeps failing
I am brand new to R and I've been trying to look around StackOverflow for an answer but have not found something that works. I would like to add a title and color to my histogram graph but it keeps on failing for some reason. I've made my data in descending order and I'd like to title both the main heading and the x-axis and y-axis with differing names. Thank you so much in advance!
Here is the code that I am using:
CompaniesOrder=c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26)
GpMean=c(9905.5789474, 8794.1052632, 4893.0526316, 3723.1052632,
3045.6069474,1518.0444211,1200.4994211,842.4464737,765.5630588,
647.6224211,543.739875,324.5206316,217.9081579,213.0212857,
168.1743158,149.2178947,136.6547895,90.5400526,66.8915333,
57.7370526,8.3272143,3.3801053,0.2194286,0,0,0)
GpMeanTreatment <- data.frame(CompaniesOrder, GpMean)
library(ggplot2)
ggplot(GpMeanTreatment, aes(x = CompaniesOrder, y = GpMean)) +
geom_bar(stat="identity")
Solution 1:[1]
ggplot(GpMeanTreatment, aes(x = CompaniesOrder, y = GpMean, fill = CompaniesOrder)) +
geom_col() +
scale_fill_gradient(low='red', high='yellow') +
labs(x = "Your X axis title", y = "Your Y axis title", title = "Your Main Title")
Hint: geom_bar(stat="identity") is just a long way of using geom_col()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |

