Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
217 views
in Technique[技术] by (71.8m points)

ggplot2 - 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

question from:https://stackoverflow.com/questions/65927422/hotw-to-use-symbols-in-geom-point-in-r

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...