ggplot中的自定义形状(geom_point) [英] Custom shape in ggplot (geom_point)
问题描述
目标
我正在尝试将geom_point
的形状更改为十字形(所以不是加/加"符号,而是死亡"十字形).
I am trying to change the shape of the geom_point
into a cross (so not a "plus/addition" sign, but a 'death' cross).
尝试
假设我有以下数据:
library(tidyverse)
df <- read.table(text="x y
1 3
2 4
3 6
4 7 ", header=TRUE)
我可以使用geom_point
中的shape
参数将形状更改为不同的形状,如下所示:
I am able to change the shape using the shape
parameter in geom_point
into different shapes, like this:
ggplot(data = df, aes(x =x, y=y)) +
geom_point(shape=2) # change shape
但是,没有选择将形状更改为十字形.
However, there is no option to change the shape into a cross.
问题
如何使用R中的ggplot将值的形状更改为十字形?
How do I change the shape of a value into a cross using ggplot in R?
推荐答案
Shape可以设置为unicode字符.下面使用骷髅和交叉骨,但您可以查找更合适的符号.
Shape can be set to a unicode character. The below uses the skull and crossbones but you can look up a more suitable symbol.
请注意,最终结果将取决于用于生成图的字体.
Note that the final result will depend on the font used to generate the plot.
ggplot(data = df, aes(x =x, y=y)) +
geom_point(shape="\u2620", size = 10)
这篇关于ggplot中的自定义形状(geom_point)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!