我想知道是否有办法用ggplot2绘制"轮廓文本",例如带有白色小边框的黑色文本,以便在背景(如地图)上轻松阅读.
理想情况下,我想要在Google地图上看到相同类型的标签:

提前感谢任何提示!
Gre*_*now 16
这是一种从包中的shadowtext函数实现一般概念的方法TeachingDemos.中间部分的代码可以包装成一个函数来简化一些事情.这个例子是由Richie Cotton的答案公然偷来的:
d <- diamonds[sample(nrow(diamonds), 10), ]
p <- ggplot(d, aes(carat, price) )
theta <- seq(pi/8, 2*pi, length.out=16)
xo <- diff(range(d$carat))/200
yo <- diff(range(d$price))/200
for(i in theta) {
p <- p + geom_text(
bquote(aes(x=carat+.(cos(i)*xo),y=price+.(sin(i)*yo),label=cut)),
size=12, colour='black' )
}
p <- p + geom_text( aes(label=cut), size=12, colour='white' )
p <- p + opts( panel.background=theme_rect(fill='green' ) )
print(p)
Run Code Online (Sandbox Code Playgroud)

不理想或非常灵活,但您可以通过绘制粗体单声道文本,然后在顶部绘制标准单声道文本来获得效果.
我使用绿色面板背景来模拟地图.
d <- diamonds[sample(nrow(diamonds), 10), ]
(p <- ggplot(d, aes(carat, price)) +
geom_text(
aes(label = cut, family = "mono", fontface = "bold"),
size = 12,
colour = "black"
) +
geom_text(
aes(label = cut, family = "mono"),
size = 12,
colour = "white"
) +
opts(panel.background = theme_rect(fill = "green"))
)
Run Code Online (Sandbox Code Playgroud)

| 归档时间: |
|
| 查看次数: |
6891 次 |
| 最近记录: |