FAQ Database Discussion Community


Bars in geom_bar have unwanted different widths when using facet_wrap

r,ggplot2,bar-chart,geom-bar
I can'd find a solution for the following problem(s). I would appreciate some help a lot! The following code produces bar charts using facet. However, due to "extra space" ggplot2 has in some groups it makes the bars much wider, even if I specify a width of 0.1 or similar....

With ggplot2, what code creates bars made of individual words and their count?

r,ggplot2,fill,geom-bar
To convey the relative frequencies of key words, I would like each "bar" in a plot to consist of one of the words repeated vertically by its frequency. The ggplot code below removes the outline of the bar and the fill, but how can I create a "stack" of words...

ggplot2 change colours in bar chart with scale_color_identity()

r,ggplot2,geom-bar
I'm using the workaround to remove diagonal lines from a ggplot legend: https://groups.google.com/forum/?fromgroups=#!topic/ggplot2/vJnF9_HBqx4 With the following data, how do I change the colours of the groups? # Create data # a<-as.data.frame(c(1,1,1,2,2)) b<-as.data.frame(c("A","A","B","B","A")) c<-as.data.frame(c(20,20,60,50,50)) a<-cbind(a,b,c) colnames(a)<-c("X","Gp","Y") # Plot # ggplot(a, aes(x=X, y=Y,fill=Gp)) + geom_bar(stat = "identity", aes(colour = "black")) + scale_color_identity()...

Grouped bar graph custom colours

r,colors,ggplot2,geom-bar
I have the following data and wish to create a grouped bar graph like so: data<-as.data.frame(c("a","b","c","a","b","c")) colnames(data)<-"Y" data$X<-c("x","x","x","y","y","y") data$Z<-c(1,2,3,1,2,3) ggplot(data, aes(x=X, y=Z, fill=Y) + geom_bar(stat="identity", colour="black", position="dodge", size=0.25, width=0.8, alpha=0.8) + scale_fill_manual(values=c("red","red","red","blue","blue","blue")) In the last line of the code I wish to change the colours of the bars - I...

ggplot2 geom_bar group stack order factor

r,colors,ggplot2,geom-bar
I am working on stack barchart and here is the test code : dat <- read.table(text=" cars trucks suvs 10 40 25 20 20 35 30 15 25 50 25 30 20 30 15", header=TRUE, as.is=TRUE) dat$day <- factor(c("Mo", "Tu", "We", "Th", "Fr"), levels=c("Mo", "Tu", "We", "Th", "Fr")) library(reshape2) library(ggplot2)...

geom_bar from min to max data value

r,plot,ggplot2,bar-chart,geom-bar
I am not sure if geom_bar is able (probably I'm not) to create the plot I need with geom_bar. I want a bar plot but not starting from 0, I have a minimum and maximum value that are to be the start and end points of each bar. Desired output...

Specific spaces between bars in a barplot - ggplot2 - R

r,ggplot2,geom-bar
I have a simple bargraph like the following a<-data.frame(x=c("total","male","female","low education", "mid education","high education","working","not working"), y=c(80,30,50,20,40,20,65,35)) a$x<-as.character(a$x) a$x<-factor(a$x,levels=unique(a$x)) ggplot(a,aes(x,y)) + geom_bar(stat="identity",fill="orange",width=0.4) + coord_flip() + theme_bw() Now , because the levels of the x axis (flipped and now seems like y ) have a relation with each other e.g male and female...

geom_bar not showing every values

r,ggplot2,data.table,geom-bar
I want to draw a bar plot, with ggplot and geom_bar, but it seems that the behavior of geom_bar is not consistent. I don't understand why. My data is a time series of precipitations: library(ggplot2) library(data.table) library(lubridate) set.seed(42) dt1 <- data.table(dateHeure=seq(ymd_hms("2014-06-04 13:30:00"), ymd_hms("2014-10-20 08:30:00"), by='1 hour'), rain=sample(c(rep(5,15), rep(10,15), rep(20,10), rep(30,...

Remove the line and the background in the two legends

r,ggplot2,legend,geom-bar
I made this plot: #data sal<-data.frame(x=factor(c(2,2,1,1),labels=c('House','Work'))) sal$id<-factor(c(2,1,2,1),labels=c('t0','t1')) sal$val<-c(305,280,290,180) sal$lim1<-c(75,75,150,150) sal$lim2<-c(150,150,300,300) #plot p<-ggplot(sal,aes(id,y=val,fill=id))+ geom_bar(stat="identity",position="dodge",width=.75)+ scale_fill_brewer(palette='Set1',type='qual',name='Time')+ theme(axis.title.x=element_blank(), axis.title.y=element_blank(),...