0

I am trying to create a geom_point graph and within a column, I have different groups. I want each group to be represented in a different way, e.g. A - Square, B - Triangle etc. Is there any way to do this?

Sample of table

Treatment Time period No. of blooms
A One 67
B One 137
C One 32
A Two 118
B Two 212
C Two 18
stefan
  • 90,330
  • 6
  • 25
  • 51
Rachel97
  • 3
  • 3
  • 1
    Hi, have you tried to use the argument `shape = Treatment` inside `aes()`? *E.g.* `geom_point(aes(..., shape = Treatment))` – Paul Jun 30 '22 at 08:54

1 Answers1

0

You can achieve your desired result by mapping on the shape aes. If you want to assign specific shapes to categories you have to do that manually using scale_shape_manual. For a list of available shapes see Aesthetic specifications.

df <- data.frame(
         Treatment = c("A", "B", "C", "A", "B", "C"),
       Time.period = c("One", "One", "One", "Two", "Two", "Two"),
     No..of.blooms = c(67L, 137L, 32L, 118L, 212L, 18L)
)

library(ggplot2)

ggplot(df, aes(Time.period, No..of.blooms, shape = Treatment)) +
  geom_point() +
  scale_shape_manual(values = c(A = 15, B = 17, C = 16))

stefan
  • 90,330
  • 6
  • 25
  • 51
  • Thanks I managed to use scale_shape_manual() to change the shapes as I wanted – Rachel97 Jun 30 '22 at 09:18
  • Say both treatment A and B do the same thing in time period one, is there anyway to group them within ggplot so they appear under the same legend item – Rachel97 Jun 30 '22 at 10:10
  • @Rachel97 if you want to do it manually you could do `scale_shape_manual(values = c(A = 15, B = 15, C = 16))`. Otherwise you might need to create a new goupping column in your data. – Paul Jun 30 '22 at 11:13