简体   繁体   中英

ggplot: dotplot with column index on y-axis and its value as dot size VS a second column value on x-axis

I have a data table that looks like this

#       A1  A2  A3  B1  B2  B3
#   1:  1   1   3   1   5   5
#   2:  2   1   3   2   6   9
#   3:  3   2   1   3   8   11
#   4:  4   2   1   4   9   15

Now I would like to use ggplot to plot on the x-axis the values of column B1, B2 and B3, using the corresponding value in column A1, A2 and A3 for the dot size and get something like this dot plot (please note, in the picture the y axis is reversed, the lables should be 3>1, 2=2 and 1>3)

How can I do it?

Something like this:?

df=read.table(text="
       A1  A2  A3  B1  B2  B3
     1   1   3   1   5   5
     2   1   3   2   6   9
     3   2   1   3   8   11
     4   2   1   4   9   15",header=T)

ggplot(gather(df[,4:6]),aes(x=key,y=value)) + 
  geom_point(aes(size=gather(df[,1:3])$value)) + 
  theme_bw() + theme(panel.grid.major = element_blank(),
                     panel.grid.minor = element_blank())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM