我有以下資料:
dput(data)
我使用以下代碼生成繪圖:
p <- ggplot(data, aes(Zscore, ID))
p geom_point(aes(colour=pval, size=Hit))
scale_color_gradientn(colours=rainbow(4), limits=c(0, 1))
geom_vline(xintercept=0, size=0.2, colour="blue", linetype="dotted")
theme(panel.background=element_rect(fill="gray95", colour="gray95"),
panel.grid.major=element_line(size=0.1,linetype='solid', colour="gray90"),
panel.grid.minor=element_line(size=0.1,linetype='solid', colour="gray90"),
axis.title.y=element_blank())
expand_limits(x=c(-2,3))
scale_x_continuous(breaks=c(-3,-2,-1,0,1,2,3))
scale_y_discrete(limits=rev(data$ID))
在輸出中,我想更改positive Zscore值的顏色(為綠色)。還要增加到hit0,10,20,25,50....
uj5u.com熱心網友回復:
下面的情節可能不是我們想要的。
- 當 Z 分數為正時顏色變為綠色意味著它應該映射到
Zscore,而不是pval; - 此外,線條的美感
size在 中已棄用ggplot2 3.4.0,我正在使用linewidth。
library(ggplot2)
p <- ggplot(data, aes(Zscore, ID))
p geom_point(aes(colour = Zscore > 0, size = Hit))
scale_color_manual(
name = 'Z-score',
labels = c("Negative", "Positive"),
values = c(`FALSE` = 'red', `TRUE` = 'green')
)
scale_size_continuous(breaks = c(0,10,20,25,50, 75, 100))
geom_vline(xintercept=0, linewidth=0.2, colour="blue", linetype="dotted")
theme(panel.background=element_rect(fill="gray95", colour="gray95"),
panel.grid.major=element_line(linewidth=0.1,linetype='solid', colour="gray90"),
panel.grid.minor=element_line(linewidth=0.1,linetype='solid', colour="gray90"),
axis.title.y=element_blank())
expand_limits(x=c(-2,3))
# scale_x_continuous(breaks=c(-3,-2,-1,0,1,2,3, 4, 5, 6))
scale_x_continuous(name = 'Z-score', breaks = pretty(data$Zscore))
scale_y_discrete(limits=rev(data$ID))

創建于 2022-11-18,使用reprex v2.0.2
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/536940.html
標籤:r图表2颜色风水点图
