我想在我的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))
请注意我的数字范围是40到30000.我在那里有很大的差异,但是,我希望在图例中至少有最大和最小的点。否则传说对小点的帮助不大。任何想法都非常感谢。
答案 0 :(得分:2)
是的,你必须在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)
结果: