我试图将一组样本的几个特征绘制成各种美学.边框颜色和圆圈的大小就是其中之一.但是,如果我尝试为这些形状设置更大的基线边框,通过设置lwd=2
,形状全部恢复到相同的大小,图例就消失了.我只是希望圆圈有更大的边框,我该怎么做?
一个例子:
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()
Run Code Online (Sandbox Code Playgroud)
从图表开始:
> testPlot +
geom_point(aes(size=sizeVar), pch=21, color='black', fill='gray') +
scale_size_manual(values=c(9,4)) + theme_bw()
Run Code Online (Sandbox Code Playgroud)
列出元素:
> 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
Run Code Online (Sandbox Code Playgroud)
现在要改变适当的元素:
> grid.edit("geom_point.points", grep=TRUE, gp=gpar(lwd=3))
Run Code Online (Sandbox Code Playgroud)