use*_*668 0 r scatter-plot ggplot2
我想在我的 ggplot 中包含更详细的图例。当前的图例并不代表我所有的点尺寸。在以下示例中:
df <- "Freq Obs NumberOfWindows
15 0.5 40
12 0.4 80
10 0.3 100
8 0.2 800
6 0.18 1300
3 0.1 2000
1 0.05 30000"
ResA <- read.table(text=df, header=T)
library(ggplot2)
ggplot(ResA, aes(Freq, Obs, size=NumberOfWindows)) +
geom_point() +
xlab("Boundary frequency") +
ylab("Average number of overlaps per window (10kb)") +
ggtitle(as.character("The plot"))+
theme_bw()+
scale_size_continuous(name="area", range = c(1,20))
Run Code Online (Sandbox Code Playgroud)
请注意,我的数字范围从 40 到 30000。我在那里有很大的差异,但是,我希望在图例中至少有最大和最小的点。否则图例对小点没有多大帮助。这里的任何想法都受到高度赞赏。
是的,你必须在你的scale_size_continuous中添加中断,如下所示:
ggplot(ResA, aes(Freq, Obs, size=NumberOfWindows)) +
geom_point() +
xlab("Boundary frequency") +
ylab("Average number of overlaps per window (10kb)") +
ggtitle(as.character("The plot"))+
theme_bw()+
scale_size_continuous(name="area",
range = c(1,20),
breaks = ResA$NumberOfWindows)
Run Code Online (Sandbox Code Playgroud)
结果: