首页 > 解决方案 > R ggplot2 geom_point 形状

问题描述

我正在使用ggplot2并希望我geom_points拥有基于数据框行的单独形状。

data <- read.csv(my_csv_path) # 
plot <- ggplot(data = data) + # in this file I have shape numbers (17 or 21) for each csv row.
 geom_point(aes(shape = shape), color = "grey20")

每行都有单独的形状,我想根据它来绘制。我的输出总是根据 csv 文件绘制三角形。

有任何想法吗 ?

谢谢 !

标签: rggplot2visualization

解决方案


希望这将适用于您的数据。如果没有,请使用 粘贴数据样本dputscale_shape_identity应用数据框中的形状编号:

library(ggplot2)
library(dplyr)

tibble(shape = 1:5, x = 1:5, y = 1) %>% 
  ggplot(aes(x, y, shape = shape)) +
  geom_point(size = 10, colour = "grey20") +
  scale_shape_identity()

reprex 包于 2020-12-15 创建(v0.3.0)


推荐阅读