无论如何要更改 R 中 ggplot 中值的大小(geom_point)?

Is there anyway to change the size of values in ggplot in R (geom_point)?

这些值会自动设置为 0.25、0.50、0.75 和 1。但是,我想更改这些范围,特别是让它们变小。这是我的代码。我还添加了一些样本数据,如您所见,p 值(我感兴趣的变量)的范围从小到“1.72e-50”到“1”。

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

#imports/scans the data from file explorer/spreadsheets 

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") +
  scale_size_continuous(range=c(1,5), trans = "reverse")
  TFRCggplot + guides(size = guide_legend(reverse = TRUE))

Here is some sample data.

structure(list(Variant = structure(c(28L, 28L, 28L, 28L, 28L, 
23L, 23L, 23L, 23L, 23L, 21L, 21L, 21L, 21L, 21L, 6L, 6L, 6L, 
6L, 6L, 8L, 8L, 8L, 8L, 8L, 10L, 10L, 10L, 10L, 10L, 14L, 14L, 
14L, 14L, 14L, 15L, 15L, 15L, 15L, 15L, 25L, 25L, 25L, 25L, 25L, 
16L, 16L, 16L, 16L, 16L, 22L, 22L, 22L, 22L, 22L, 9L, 9L, 9L, 
9L, 9L, 7L, 7L, 7L, 7L, 7L, 19L, 19L, 19L, 19L, 19L, 11L, 11L, 
11L, 11L, 11L, 1L, 1L, 1L, 1L, 1L, 20L, 20L, 20L, 20L, 20L, 27L, 
27L, 27L, 27L, 27L, 5L, 5L, 5L, 5L, 5L, 12L, 12L, 12L, 12L, 12L, 
26L, 26L, 26L, 26L, 26L, 24L, 24L, 24L, 24L, 24L, 3L, 3L, 3L, 
3L, 3L, 4L, 4L, 4L, 4L, 4L, 13L, 13L, 13L, 13L, 13L, 29L, 29L, 
29L, 29L, 29L, 17L, 17L, 17L, 17L, 17L, 18L, 18L, 18L, 18L, 18L, 
2L, 2L, 2L, 2L, 2L), .Label = c("rs140316777", "rs141165322", 
"rs144131234", "rs149088653", "rs184956956", "rs199637290", "rs200128950", 
"rs201408488", "rs34490397", "rs3817672", "rs41295849", "rs41295879", 
"rs41298067", "rs41301381", "rs41303529", "rs533268185", "rs534595346", 
"rs536971550", "rs537759332", "rs539830157", "rs541010181", "rs541398971", 
"rs545061104", "rs559739602", "rs563942755", "rs571673598", "rs572837317", 
"rs576156970", "rs577771580"), class = "factor"), Position = c(66L, 
66L, 66L, 66L, 66L, 90L, 90L, 90L, 90L, 90L, 138L, 138L, 138L, 
138L, 138L, 141L, 141L, 141L, 141L, 141L, 312L, 312L, 312L, 312L, 
312L, 426L, 426L, 426L, 426L, 426L, 636L, 636L, 636L, 636L, 636L, 
762L, 762L, 762L, 762L, 762L, 810L, 810L, 810L, 810L, 810L, 831L, 
831L, 831L, 831L, 831L, 879L, 879L, 879L, 879L, 879L, 891L, 891L, 
891L, 891L, 891L, 975L, 975L, 975L, 975L, 975L, 1002L, 1002L, 
1002L, 1002L, 1002L, 1011L, 1011L, 1011L, 1011L, 1011L, 1056L, 
1056L, 1056L, 1056L, 1056L, 1137L, 1137L, 1137L, 1137L, 1137L, 
1143L, 1143L, 1143L, 1143L, 1143L, 1221L, 1221L, 1221L, 1221L, 
1221L, 1260L, 1260L, 1260L, 1260L, 1260L, 1692L, 1692L, 1692L, 
1692L, 1692L, 1791L, 1791L, 1791L, 1791L, 1791L, 1794L, 1794L, 
1794L, 1794L, 1794L, 1815L, 1815L, 1815L, 1815L, 1815L, 2031L, 
2031L, 2031L, 2031L, 2031L, 2070L, 2070L, 2070L, 2070L, 2070L, 
2103L, 2103L, 2103L, 2103L, 2103L, 2172L, 2172L, 2172L, 2172L, 
2172L, 2259L, 2259L, 2259L, 2259L, 2259L), Geographical.Location = structure(c(1L, 
2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 
3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 
4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 
5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 
1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 
2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 
3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 
4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 
5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L
), .Label = c("AFR", "AMR", "EAS", "EUR", "SAS"), class = "factor"), 
    Frequency = c(0, 0, 0.202, 0, 0, 0, 0.295, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 0.192, 0, 0, 0, 0, 0.384, 7.654, 5.934, 30.13571429, 
    58.955, 26.458, 4.008, 0.598, 0, 0, 3.782, 0, 0.196, 0.1328571429, 
    0, 0, 4.056, 5.592, 0, 0, 0, 0, 0.196, 0.1257142857, 0, 0, 
    0, 0, 0, 0, 0, 1.414, 0.404, 0.2814285714, 0.24, 0, 0, 0, 
    0, 0.265, 0, 0, 0, 0.3357142857, 0, 0, 0, 0, 0, 0, 1.188, 
    0, 0.232, 0.4414285714, 0, 0, 0, 0, 0, 0.5875, 0, 0.186, 
    0, 0, 0, 0, 0.186, 0, 0, 0, 0.572, 0, 0, 7.765714286, 0.265, 
    0, 0, 0, 0, 0, 0, 0, 0, 0.1442857143, 0, 0, 0, 0, 0.2528571429, 
    0, 0, 0.56, 0, 0.2885714286, 0, 0, 0, 2.692, 0.1328571429, 
    0, 0, 0.422, 0, 0.1442857143, 0, 0, 0, 0, 0.1485714286, 0, 
    0, 0, 0, 0, 0, 0, 0, 0.232, 0, 0, 0, 0, 0), p.value = c(1, 
    1, 0.201, 1, 1, 1, 0.139, 1, 1, 1, 1, 1, 1, 1, 0.195, 1, 
    1, 0.201, 1, 1, 0.579, 1, 0.183, 0.59, 0.173, 2.69e-30, 1.03e-05, 
    3.1e-31, 1.72e-50, 3.62e-08, 0.00641, 0.0959, 4.49e-14, 0.0205, 
    0.0357, 0.264, 1, 1, 1, 1, 1, 1, 1, 0.201, 1, 0.264, 1, 1, 
    1, 1, 1, 1, 1, 1, 0.195, 0.172, 0.361, 1, 1, 1, 1, 0.139, 
    1, 1, 1, 0.0696, 1, 1, 1, 1, 0.351, 1, 6.49e-05, 0.607, 0.604, 
    0.0183, 1, 1, 1, 1, 0.579, 0.0949, 0.589, 0.182, 1, 1, 1, 
    1, 1, 0.195, 0.571, 1, 0.00812, 1, 1, 7.27e-30, 0.00741, 
    1.28e-05, 1.27e-05, 1.26e-05, 0.334, 1, 0.59, 0.59, 0.000279, 
    0.264, 1, 1, 1, 1, 0.0696, 1, 1, 1, 1, 0.0696, 1, 1, 1, 1, 
    0.264, 1, 1, 1, 1, 0.264, 1, 1, 1, 1, 0.264, 1, 1, 1, 1, 
    1, 1, 1, 1, 0.195, 1, 1, 1, 0.201, 1)), row.names = c(NA, 
145L), class = "data.frame")
>  dput(head(TFRC,150))
structure(list(Variant = structure(c(28L, 28L, 28L, 28L, 28L, 
23L, 23L, 23L, 23L, 23L, 21L, 21L, 21L, 21L, 21L, 6L, 6L, 6L, 
6L, 6L, 8L, 8L, 8L, 8L, 8L, 10L, 10L, 10L, 10L, 10L, 14L, 14L, 
14L, 14L, 14L, 15L, 15L, 15L, 15L, 15L, 25L, 25L, 25L, 25L, 25L, 
16L, 16L, 16L, 16L, 16L, 22L, 22L, 22L, 22L, 22L, 9L, 9L, 9L, 
9L, 9L, 7L, 7L, 7L, 7L, 7L, 19L, 19L, 19L, 19L, 19L, 11L, 11L, 
11L, 11L, 11L, 1L, 1L, 1L, 1L, 1L, 20L, 20L, 20L, 20L, 20L, 27L, 
27L, 27L, 27L, 27L, 5L, 5L, 5L, 5L, 5L, 12L, 12L, 12L, 12L, 12L, 
26L, 26L, 26L, 26L, 26L, 24L, 24L, 24L, 24L, 24L, 3L, 3L, 3L, 
3L, 3L, 4L, 4L, 4L, 4L, 4L, 13L, 13L, 13L, 13L, 13L, 29L, 29L, 
29L, 29L, 29L, 17L, 17L, 17L, 17L, 17L, 18L, 18L, 18L, 18L, 18L, 
2L, 2L, 2L, 2L, 2L), .Label = c("rs140316777", "rs141165322", 
"rs144131234", "rs149088653", "rs184956956", "rs199637290", "rs200128950", 
"rs201408488", "rs34490397", "rs3817672", "rs41295849", "rs41295879", 
"rs41298067", "rs41301381", "rs41303529", "rs533268185", "rs534595346", 
"rs536971550", "rs537759332", "rs539830157", "rs541010181", "rs541398971", 
"rs545061104", "rs559739602", "rs563942755", "rs571673598", "rs572837317", 
"rs576156970", "rs577771580"), class = "factor"), Position = c(66L, 
66L, 66L, 66L, 66L, 90L, 90L, 90L, 90L, 90L, 138L, 138L, 138L, 
138L, 138L, 141L, 141L, 141L, 141L, 141L, 312L, 312L, 312L, 312L, 
312L, 426L, 426L, 426L, 426L, 426L, 636L, 636L, 636L, 636L, 636L, 
762L, 762L, 762L, 762L, 762L, 810L, 810L, 810L, 810L, 810L, 831L, 
831L, 831L, 831L, 831L, 879L, 879L, 879L, 879L, 879L, 891L, 891L, 
891L, 891L, 891L, 975L, 975L, 975L, 975L, 975L, 1002L, 1002L, 
1002L, 1002L, 1002L, 1011L, 1011L, 1011L, 1011L, 1011L, 1056L, 
1056L, 1056L, 1056L, 1056L, 1137L, 1137L, 1137L, 1137L, 1137L, 
1143L, 1143L, 1143L, 1143L, 1143L, 1221L, 1221L, 1221L, 1221L, 
1221L, 1260L, 1260L, 1260L, 1260L, 1260L, 1692L, 1692L, 1692L, 
1692L, 1692L, 1791L, 1791L, 1791L, 1791L, 1791L, 1794L, 1794L, 
1794L, 1794L, 1794L, 1815L, 1815L, 1815L, 1815L, 1815L, 2031L, 
2031L, 2031L, 2031L, 2031L, 2070L, 2070L, 2070L, 2070L, 2070L, 
2103L, 2103L, 2103L, 2103L, 2103L, 2172L, 2172L, 2172L, 2172L, 
2172L, 2259L, 2259L, 2259L, 2259L, 2259L), Geographical.Location = structure(c(1L, 
2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 
3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 
4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 
5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 
1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 
2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 
3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 
4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 
5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L
), .Label = c("AFR", "AMR", "EAS", "EUR", "SAS"), class = "factor"), 
    Frequency = c(0, 0, 0.202, 0, 0, 0, 0.295, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 0.192, 0, 0, 0, 0, 0.384, 7.654, 5.934, 30.13571429, 
    58.955, 26.458, 4.008, 0.598, 0, 0, 3.782, 0, 0.196, 0.1328571429, 
    0, 0, 4.056, 5.592, 0, 0, 0, 0, 0.196, 0.1257142857, 0, 0, 
    0, 0, 0, 0, 0, 1.414, 0.404, 0.2814285714, 0.24, 0, 0, 0, 
    0, 0.265, 0, 0, 0, 0.3357142857, 0, 0, 0, 0, 0, 0, 1.188, 
    0, 0.232, 0.4414285714, 0, 0, 0, 0, 0, 0.5875, 0, 0.186, 
    0, 0, 0, 0, 0.186, 0, 0, 0, 0.572, 0, 0, 7.765714286, 0.265, 
    0, 0, 0, 0, 0, 0, 0, 0, 0.1442857143, 0, 0, 0, 0, 0.2528571429, 
    0, 0, 0.56, 0, 0.2885714286, 0, 0, 0, 2.692, 0.1328571429, 
    0, 0, 0.422, 0, 0.1442857143, 0, 0, 0, 0, 0.1485714286, 0, 
    0, 0, 0, 0, 0, 0, 0, 0.232, 0, 0, 0, 0, 0), p.value = c(1, 
    1, 0.201, 1, 1, 1, 0.139, 1, 1, 1, 1, 1, 1, 1, 0.195, 1, 
    1, 0.201, 1, 1, 0.579, 1, 0.183, 0.59, 0.173, 2.69e-30, 1.03e-05, 
    3.1e-31, 1.72e-50, 3.62e-08, 0.00641, 0.0959, 4.49e-14, 0.0205, 
    0.0357, 0.264, 1, 1, 1, 1, 1, 1, 1, 0.201, 1, 0.264, 1, 1, 
    1, 1, 1, 1, 1, 1, 0.195, 0.172, 0.361, 1, 1, 1, 1, 0.139, 
    1, 1, 1, 0.0696, 1, 1, 1, 1, 0.351, 1, 6.49e-05, 0.607, 0.604, 
    0.0183, 1, 1, 1, 1, 0.579, 0.0949, 0.589, 0.182, 1, 1, 1, 
    1, 1, 0.195, 0.571, 1, 0.00812, 1, 1, 7.27e-30, 0.00741, 
    1.28e-05, 1.27e-05, 1.26e-05, 0.334, 1, 0.59, 0.59, 0.000279, 
    0.264, 1, 1, 1, 1, 0.0696, 1, 1, 1, 1, 0.0696, 1, 1, 1, 1, 
    0.264, 1, 1, 1, 1, 0.264, 1, 1, 1, 1, 0.264, 1, 1, 1, 1, 
    1, 1, 1, 1, 0.195, 1, 1, 1, 0.201, 1)), row.names = c(NA, 
145L), class = "data.frame")

问题的主要问题是使要点更易于阅读。 在评论中提出的建议解决了这个问题。

第二个问题是让图例将 log10 标签显示为 10 的幂。由于我还没有找到解决这个问题的方法,所以在 Whosebug 帖子中肯定没有,这里就是。它使用 scales::math_format 的方式与用于轴标签的方式不同。

library(ggplot2)
library(scales)

TFRCggplot <- ggplot(TFRC, aes(Position, Frequency)) +
  geom_jitter(aes(colour = Geographical.Location, size = log10(p.value))) +
  labs(subtitle="Frequency of Various Polymorphisms", title="TFRC") +
  scale_size_continuous(range = c(1, 5), 
                        breaks = seq(0, -50, by = -10),
                        labels = math_format(10^.x),
                        trans = "reverse")

TFRCggplot + guides(size = guide_legend(reverse = TRUE))