I want to be able to remove the white space between bars in a bar
plot (geom_bar) in which the width of the bars are determined by the
Number of participants. I have tried position = 'dodge' but it did
not work the way I want it to work.
This is what my current graph looks like:
Here is my reproducible example
library(ggplot2)
MyFile<- structure(list(ethnic = structure(c(5L, 3L, 1L, 4L, 2L),
.Label = c("Asian", "Black", "Hispanic",
"Other", "White"), class = "factor"),
district = c(85L, 8L, 3L, 3L, 1L),
ap.course = c(86L, 4L, 6L, 3L, 1L)),
.Names = c("ethnic", "district", "ap.course"),
class = "data.frame",
row.names = c(NA,-5L))
attach(MyFile)
MyFile$prop<-ap.course/district
MyFile$w<- (.05+log(MyFile$ap.course))*.3
# add .5 because otherwise black does not show up
#multiply by 30% because otherwise the default spacing is odd
ggplot(MyFile, aes(x=ethnic,y=prop,, width=w), binwidth=0)+
geom_bar(aes(fill=ethnic), stat="identity", position="dodge",
width = 10 )+
labs(x="Ethnicity ", y="Risk Ratio ")+
theme_classic()
This is the way I want the graph to look
Any ideas would be appreciated.
--
Sincerely,
Ben Ditkowsky, Ph. D.
MeasuredEffects.com