Plot characters(Letters) according to their frequency in R

Viewed 75

I have data frame like this:

df<-data.frame(
  "name" = c("P1", "P1", "P1","P2", "P2", "P2", "P3", "P3"),
  "value"=c("I", "V", "A", "C", "H", "1", "L", "P"),
  "Freq"=c("70.7", "29.3", "1.41", "0.7", "0.3", "90.2", "50.5", "40.4"))
df

I want to plot the values as letters and their size should represents the Frequency column. So I want plot like this : enter image description here

I'm using ggplot2 but I don't know which geom to use to make the letters. Can you please help me?

2 Answers

Maybe you want something like this. You can use this code:

df<-data.frame(
  "name" = c("P1", "P1", "P1","P2", "P2", "P2", "P3", "P3"),
  "value"=c("I", "V", "A", "C", "H", "1", "L", "P"),
  "Freq"=c("70.7", "29.3", "1.41", "0.7", "0.3", "90.2", "50.5", "40.4"))

df %>%
  ggplot(aes(x = name, y = Freq, label = value)) +
  geom_blank() +
  geom_text(aes(size = Freq)) +
  theme(legend.position="none",
        panel.background = element_rect(fill = "white"))

Output:

enter image description here

in case some one is having the same question, I found motifstack package can do the job. Thank you!

BiocManager::install("jianhong/motifStack")
Related