user330
user330

Reputation: 1290

Hotw to use symbols in geom_point in R

A small sample of the data is:

df<-read.table (text=" N    SO  Value
1   A1  12
2   A1  14
3   A1  16
4   A1  18
5   A1  20
6   B1  22
7   B1  24
8   B1  26
9   B1  28
10  B1  30

", header=TRUE)

I want to use the greek symbol of alpha (α) and beta (β) instead of red and blue circles on the lines

I have used these codes:

ggplot(df,aes(x=N,y=Value)) +geom_point(size=3,aes(colour=SO)) +geom_line(aes(colour = SO))

Thanks for your help

Upvotes: 0

Views: 196

Answers (1)

neilfws
neilfws

Reputation: 33802

You can use geom_text with the option parse = TRUE to add symbols as labels.

Assuming that you want alpha where SO = A1 and beta where SO = B1, something like this:

library(dplyr)
library(ggplot2)

df %>% 
  mutate(label = ifelse(SO == "A1", "alpha", "beta")) %>% 
  ggplot(aes(N, Value)) + 
  geom_line(aes(colour = SO)) + 
  geom_text(aes(label = label), parse = TRUE)

Result:

enter image description here

Upvotes: 4

Related Questions