【发布时间】:2017-08-10 15:26:15
【问题描述】:
美好的一天。
我正在使用 ggplot2 绘制 REVIGO 生成的结果的散点图。
我想在散点图中增加重要节点的大小(附图)。例如,log10_p_value 为 -12.5 的节点应该是最大的(橙色框),但在图中并非如此。
我一直在寻找解决方案,但到目前为止我还没有运气。你能和我分享你的经验吗?我还是 ggplot2 的新手。我包括了下面的代码。
library( ggplot2 )
library( scales )
names11 <- c("term_ID","description","frequency_%","plot_X","plot_Y","plot_size","log10_p_value","uniqueness","dispensability");
data11 <- rbind(c("GO:0009628","response to abiotic stimulus", 0.312, 5.840,-1.260, 5.190,-14.1565,0.454,0.000),
c("GO:0019538","protein metabolic process",12.328,-4.835,-0.256, 6.788,-2.4535,0.765,0.000),
c("GO:0030154","cell differentiation", 0.281,-0.789,-6.684, 5.146,-3.4926,0.536,0.000),
c("GO:0016049","cell growth", 0.035,-1.034, 6.318, 4.241,-3.2145,0.717,0.073),
c("GO:0009719","response to endogenous stimulus", 0.113, 5.811, 1.214, 4.750,-2.8560,0.471,0.353),
c("GO:0006950","response to stress", 4.119, 6.192,-0.112, 6.312,-11.1427,0.415,0.494));
one.data11 <- data.frame(data11);
names(one.data11) <- names11;
one.data11 <- one.data11 [(one.data11$plot_X != "null" & one.data11$plot_Y != "null"), ];
one.data11$plot_X <- as.numeric( as.character(one.data11$plot_X) );
one.data11$plot_Y <- as.numeric( as.character(one.data11$plot_Y) );
one.data11$plot_size <- as.numeric( as.character(one.data11$plot_size) );
one.data11$log10_p_value <- as.numeric( as.character(one.data11$log10_p_value) );
one.data11$frequency <- as.numeric( as.character(one.data11$frequency) );
one.data11$uniqueness <- as.numeric( as.character(one.data11$uniqueness) );
one.data11$dispensability <- as.numeric( as.character(one.data11$dispensability) );
# --------------------------------------------------------------------------
p11 <- ggplot( data = one.data11 );
p11 <- p11 + geom_point( aes( plot_X, plot_Y, colour = log10_p_value, size = log10_p_value), alpha = I(0.6) ) + scale_size_area();
# Change the gradient colour
p11 <- p11 + scale_colour_gradient( low = "navyblue", high = "blue", limits = c( min(one.data11$log10_p_value), 0) );
p11 <- p11 + geom_point( aes(plot_X, plot_Y, size = log10_p_value), shape = 21, fill = "transparent", colour = I (alpha ("black", 0.6) )) + scale_size_area();
# Adjust the plot scale size
p11 <- p11 + scale_size( range=c(3, 18)) + theme_bw();
ex11 <- one.data11 [ one.data11$dispensability < 0.15, ];
# Adjust position of the plot text label with the vjust and hjust aesthetics
# 0 (right/bottom); 1 (top/left) ; ("left", "middle", "right", "bottom", "center", "top")
# Inward always aligns text towards the center
# Outward aligns it away from the center
p11 <- p11 + geom_text( data = ex11, aes(plot_X, plot_Y, label = description), colour = I(alpha("black", 0.85)), size = 4, check_overlap = TRUE, vjust = "middle", hjust = "inward");
p11 <- p11 + labs (y = "semantic space x", x = "semantic space y");
p11 <- p11 + theme(legend.key = element_blank()) ;
one.x_range = max(one.data11$plot_X) - min(one.data11$plot_X);
one.y_range = max(one.data11$plot_Y) - min(one.data11$plot_Y);
p11 <- p11 + xlim(min(one.data11$plot_X)-one.x_range/10,max(one.data11$plot_X)+one.x_range/10);
p11 <- p11 + ylim(min(one.data11$plot_Y)-one.y_range/10,max(one.data11$plot_Y)+one.y_range/10);
# --------------------------------------------------------------------------
# Output the plot to screen
p11;
ggsave("scaterPlot11.tiff", dpi=300);
感谢您的宝贵时间。
【问题讨论】:
标签: r ggplot2 scatter-plot