R 忽略带有ggplot2的数字符号

R 忽略带有ggplot2的数字符号,r,ggplot2,tidyverse,R,Ggplot2,Tidyverse,我有以下建议: gene = c("a", "b", "c", "d") fc = c(-1, -2, 1, 2) df = data.frame(gene, fc) 我使用以下代码进行绘图: ggplot(df, aes(gene, fc)) + geom_point(size=df$fc) + theme_minimal() 打印时,如何忽略“fc”中值的符号 谢谢您可以使用绝对值函数abs()忽略负号。比如说 ggplot(df, aes(gene, fc)) + geom_po

我有以下建议:

gene = c("a", "b", "c", "d")
fc = c(-1, -2, 1, 2)
df = data.frame(gene, fc)
我使用以下代码进行绘图:

ggplot(df, aes(gene, fc)) + geom_point(size=df$fc) + theme_minimal()
打印时,如何忽略“fc”中值的符号


谢谢

您可以使用绝对值函数
abs()
忽略负号。比如说

ggplot(df, aes(gene, fc)) + 
  geom_point(aes(size=abs(fc))) + 
  theme_minimal()

只需确保始终将要映射到数据的属性放入
aes()
中即可。你很少会在ggplot代码中看到
$

你只是想要
几何点(aes(size=abs(fc))
abs()取数字的绝对值(它会去掉负号)。非常感谢:)