Hello Everyone,
I am a total beginner and i need your help. I should create a bar plot with an adapted width. Ideally also circular. How can I change the width of ggplot? Thank you for your help.
Hi,
Welcome to the forum. Use 'width' in geom_col()
or geom_bar
to tweak the bar width and for circular behavior, just add coord_polar
Here are some simple examples, which you can adapt to your data.
library(ggplot2)
library(dplyr)
#modified width bar Chart
slices <- c(10, 12, 4, 16, 8)
lbls <- c("US", "UK", "Australia", "Germany", "France")
DF <- data.frame(lbls = lbls,
slices = slices)
p <- ggplot(DF, aes(x = lbls, y = slices, fill = lbls))
#compare column width
p+ geom_col(width = 0.5)
p + geom_col(width = 1)
#circular
#for geom_col x = 1 because geom_col defaults to "identity"
pp <-ggplot(DF, aes(x = 1, y = slices, fill = lbls))
pp + geom_col(width = 1) + coord_polar(theta = "x" )
pp + geom_col(width = 1) + coord_polar(theta = "y" )
Hope this helps.
JW
Many thanks for the quick response. I am now a proud creator of a circular barplot
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.