2 questions on try to plot data as a stacked bar chart

45 views
Skip to first unread message

AA

unread,
May 17, 2014, 6:11:26 PM5/17/14
to ggp...@googlegroups.com
First question - I would like to plot data like a stacked barchart, except ggplot seems to only have the y-axis as "count", not based on values.
 
Essentially, I would like to plot my data like the two-color graph on this page: http://docs.ggplot2.org/current/geom_bar.html, entitled "Stacked bar charts".  I want the barcharts to scale to the integer values of my data set (not count).
 
I've attached the example data set that I'm using.
 
Here's the R code that I've tried to use so far:
 

rawdata <- read.csv (file="example_pivot.csv", header=TRUE)
#### look to see what the data looks like
str(rawdata)
head(rawdata)
library(ggplot2)
     
# Stacked bar charts are easy in ggplot2, but not effective visually,
stackedbarchart <- ggplot(rawdata, aes(Person, fill=Status)) + geom_bar() +
    theme(panel.grid.major=element_blank(),plot.background=element_blank(),
        panel.grid.minor=element_blank(),axis.title = element_text(face = "bold",
        size = 12),axis.text = element_text(colour = "black"))
stackedbarchart       

 
 
example_pivot.csv

Dennis Murphy

unread,
May 18, 2014, 2:07:42 AM5/18/14
to AA, ggplot2
Hi:

The magic incantation is 'stat = identity':

#---
DF <- read.csv("example_pivot.csv", header = TRUE)

library(ggplot2)

ggplot(DF, aes(x = Person, y = Budget, fill = Status)) +
geom_bar(stat = "identity") +
theme(panel.grid.major=element_blank(),
plot.background=element_blank(),
panel.grid.minor=element_blank(),
axis.title = element_text(face = "bold", size = 12),
axis.text = element_text(colour = "black"))
#---


Dennis
> --
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example:
> https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ggplot2" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ggplot2+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages