简体   繁体   中英

Is there a way to change range of size values in ggplot2 (geom_point) in R?

I am unsure of how to set the size of geom_point in R ggplot in my bubble chart. One of my numerical variables is p-value, and the smallest bubbles are automatically plotted from the smallest p-values, but I would like to make it so that the largest p-values are shown by the smallest size of bubble on the plot.

在此处输入图片说明

I've tried using p + guides(size= guide_legend(reverse = TRUE)) but this just changes the order of the size of bubbles on the legend.

library(ggplot2)
data(TFRC, package="ggplot2") 

TFRC <- read.csv(file.choose(), header = TRUE)

# bubble chart showing position of polymorphisms on gene, the frequency of each of these polymorphisms, where they are prominent on earth, and p-value 

TFRCggplot <- ggplot(TFRC, aes(Position, Frequency))+
  geom_jitter(aes(col=Geographical.Location, size=p.value))+
  labs(subtitle="Frequency of Various Polymorphisms", title="TFRC")
  TFRCggplot + guides(size = guide_legend(reverse = TRUE))

See ?scale_size_continuous .

You could try reversing the range values:

library(tibble)
library(ggplot2)

tibble(x = 1:5, 
       y = c(0.001, 0.01, 0.05, 0.1, 1)) %>% 
  ggplot(aes(x, y)) + 
  geom_point(aes(size = y)) + 
  scale_size_continuous(range = c(6, 1))

在此处输入图片说明

Or you could try trans = "reverse" :

tibble(x = 1:5, 
       y = c(0.001, 0.01, 0.05, 0.1, 1)) %>% 
  ggplot(aes(x, y)) + 
  geom_point(aes(size = y)) + 
  scale_size_continuous(trans = "reverse")

在此处输入图片说明

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