X axis squished

583 views
Skip to first unread message

Helen Kamens-Horton

unread,
Dec 3, 2014, 9:51:43 AM12/3/14
to ggp...@googlegroups.com
I'm relatively new to ggplot2.  I'm trying to make a bar graph, but my x axis gets squashed.  The resulting graph is attached as a pdf.  Any idea on how I can get rid of the extra white space on the right side of the graph?

LOCO_BT <- read.csv ("ForGraphs.csv", header = TRUE)

### GET SUMMARY STATISTICS TO MAKE GRAPHS

LOCO <- summarySE(LOCO_BT, measurevar="Diff_BC", groupvars=c("Genotype","DUM_Dose"), na.rm = TRUE)
LOCO

### CREATE A SHORT CUT TO MAKE BLACK/WHITE GRAPHS

BW_Graphs <- theme_bw()+
  theme(
    plot.background = element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    panel.border = element_blank()) +
  theme(axis.line = element_line(color = 'black'))


### GRAPH WITH MEAN +/- SEM 

ggplot(LOCO, aes(x=DUM_Dose, y=Diff_BC, fill=(factor(C57_LOCO$Genotype, levels=c("WT", "HET", "KO"))))) + 
  geom_bar(position=position_dodge(.9), 
           stat="identity",
           colour="black", # Use black outlines,
           size=.3) +
  scale_fill_manual(breaks=c("WT", "HET", "KO"),
                    values=c("white", "gray", "black"),
                    name="Genotype") +
  geom_errorbar(aes(ymin=Diff_BC-se, ymax=Diff_BC+se), # Need to change for future graphs to variable of interest eg Diff_BC
                size=.3,        #Thinner lines
                width=.2,       # Width of the error bars
                position=position_dodge(.9)) +
  xlab("Dose") +
  ylab("Beam Crosses") +
  ggtitle("Activity") +
  scale_y_continuous (limits=c(-125, 25), expand = c(0, 0)) +
  scale_x_discrete(breaks=c("1", "2", "3"), labels=c("0.25", "0.5", "1.0"))+
  BW_Graphs


Here is an example of what I get from my summarySE

Genotype DUM_Dose  N     Diff_BC       sd        se       ci
1      HET        1 16  -20.250000 48.78046 12.195115 25.99327
2      HET        2 15  -69.133333 43.72947 11.290901 24.21657


Activity.pdf

Helen Kamens

unread,
Dec 3, 2014, 7:44:50 PM12/3/14
to ggp...@googlegroups.com
In case anyone else has this problem this small change in the code fixed it:

scale_x_discrete(breaks=c("1", "2", "3"), labels=c("0.25", "0.5", "1.0"), limits=c(1,2,3))

Just to be clear there should have only been 3 categories on the X-axis.  The problem I was have made it seems like there should have been a 4th category that wasn't appearing.
Reply all
Reply to author
Forward
0 new messages