Warm tip: This article is reproduced from serverfault.com, please click

R ggplot2 geom_point shapes

发布于 2020-12-15 10:35:20

I am working with ggplot2 and want my geom_points to have individual shapes based on dataframe rows.

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")

Each row has individial shape and I want to draw based on it. My output always draws triangles, based on csv file.

Any ideas ?

Thanks !

Questioner
varguy
Viewed
0
Andrew Baxter 2020-12-15 21:29:13

Hopefully this will work with your data. If not, do paste a sample of the data using dput. scale_shape_identity applies the shape numbers from the dataframe:

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()

Created on 2020-12-15 by the reprex package (v0.3.0)