I am trying to plot several features of a group of samples to various aesthetics. Border color and size of a circle is one of them. However, if I try to set a larger baseline border for these shapes, by setting lwd=2
, the shapes all revert to the same size and the legend is gone. I just want the circles to have a larger border, how can I do this?
An example:
library(ggplot2)
testFrame <- data.frame(
sizeVar=factor(c('a', 'a', 'a', 'a', 'b', 'b', 'b', 'b')),
samples=rep(c('Sample1', 'Sample2'), times=4),
features=c(rep('Feature1', times=4), rep('Feature2', times=4))
)
testPlot <- ggplot(data=testFrame, aes(x=samples, y=features))
testPlot +
geom_point(aes(size=sizeVar), pch=21, color='black', fill='gray') +
scale_size_manual(values=c(9,4)) + theme_bw()
testPlot +
geom_point(aes(size=sizeVar), pch=21, lwd=3, color='black', fill='gray') +
scale_size_manual(values=c(9,4)) + theme_bw()
To change the Size of Legend, we have to add guides() and guide_legend() functions to the geom_point() function.
aes() is a quoting function. This means that its inputs are quoted to be evaluated in the context of the data. This makes it easy to work with variables from the data frame because you can name those directly. The flip side is that you have to use quasiquotation to program with aes() .
Colour and fillThe size of the filled part is controlled by size , the size of the stroke is controlled by stroke . Each is measured in mm, and the total size of the point is the sum of the two. Note that the size is constant along the diagonal in the following figure.
Start with your graph:
> testPlot +
geom_point(aes(size=sizeVar), pch=21, color='black', fill='gray') +
scale_size_manual(values=c(9,4)) + theme_bw()
List the elements:
> grid.ls()
GRID.gTableParent.162
background.1-6-6-1
spacer.4-3-4-3
panel.3-4-3-4
grill.gTree.126
panel.background.rect.121
panel.grid.major.y.polyline.123
panel.grid.major.x.polyline.125
geom_point.points.116
panel.border.rect.118
axis-l.3-3-3-3
axis.line.y.zeroGrob.136
axis
axis-b.4-4-4-4
axis.line.x.zeroGrob.130
axis
xlab.5-4-5-4
ylab.3-2-3-2
guide-box.3-5-3-5
title.2-4-2-4
Now to change the appropriate element:
> grid.edit("geom_point.points", grep=TRUE, gp=gpar(lwd=3))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With