1
votes

I'm using ggplot2 with both + geom_line() + geom_point(). I have the colors/shapes worked out, but I can't scale the legend appropriately. If I do nothing it's tiny, and if I enlarge it, the color blocks the shape.

For example: enter image description here

You can see that the shapes and colors are both in the legend, but the shapes are being drawn over by the colors. I would like to have shapes of the appropriate color drawn in the legend, but can't figure out how to do it.

My plot is being drown as follows:

ggplot(data=melted, aes(x=gene, y=value, colour=variable, shape=variable, group = variable, stroke=3, reorder(gene, value))) 
+ theme_solarized() 
+ scale_colour_solarized("blue") 
+ geom_line() 
+ geom_point() 
+ theme(axis.text.x = element_text(angle = 90, hjust = 1), plot.title = element_text(size=16, face="bold"), legend.title=element_blank(), legend.text=element_text(size=20)) 
+ ggtitle('Signiture Profiles') 
+ labs(x="Gene", y=expression(paste("Expression"), title="Expression"))  
+ scale_colour_manual(name = "Virus / Time", labels = c("Mock", "ACali09_day1", "ACali09_day3", "ACali09_day8", "AShng113_day1", "AShng113_day3", "AShng113_day8", "AChkShng113_day1", "AChkShng113_day3", "AChkShng113_day8"), values = c("#ff420e","#89da59","#89da59","#89da59","#376467","#376467","#376467","#00293c","#00293c","#00293c")) 
+ scale_shape_manual(name = "Virus / Time", labels = c("Mock", "ACali09_day1", "ACali09_day3", "ACali09_day8", "AShng113_day1", "AShng113_day3", "AShng113_day8", "AChkShng113_day1", "AChkShng113_day3", "AChkShng113_day8"), values = c(0,1,2,3,1,2,3,1,2,3)) 
+ guides(colour = guide_legend(override.aes = list(size=12)))

Here is some example data as requested:Example Data

Thanks in advance for any help you can provide.

1
Can you add an example dataset to your question that we can use? - aosmith
Try: guides(shape = guide_legend(override.aes = list(size=12))) instead of guides(colour = guide_legend(override.aes = list(size=12))) - Mosquite
@Mosquite Good idea, unfortunately it didn't change anything. :( - Adam Price
@aosmith Added example data. - Adam Price

1 Answers

2
votes

You could perhaps rethink how you are differentiating your variables. You could do something like the following. Note the changes in the first line, where I have separated the component parts of variable rather than setting colours and shapes via your scale statements. (I haven't got your theme, so I left that out).

ggplot(data=melted, aes(x=gene, 
                        y=value, 
                        colour=gsub("_.*","",variable), 
                        shape=gsub(".*_","",variable), 
                        group = variable, 
                        stroke=3, 
                        reorder(gene, value))) +
  geom_line() +
  geom_point() +
  theme(axis.text.x = element_text(angle = 90, hjust = 1), 
        plot.title = element_text(size=16, face="bold"), 
        legend.title=element_blank(), 
        legend.text=element_text(size=20)) +
  ggtitle('Signiture Profiles') +
  labs(x="Gene", y=expression(paste("Expression"), title="Expression")) + 
  guides(shape = guide_legend(override.aes = list(size=5)),
         colour = guide_legend(override.aes = list(size=5)))

enter image description here