使用 ggplot2 绘制连续数据时,有没有办法在轴上包含字符值?我已经审查了数据,例如:
x y Freq
1 -3 16 3
2 -2 12 4
3 0 10 6
4 2 7 7
5 2 4 3
Run Code Online (Sandbox Code Playgroud)
最后一行数据经过右删失。我正在使用下面的代码绘制此图以生成以下图:
a1 = data.frame(x=c(-3,-2,0,2,2), y=c(16,12,10,7,4), Freq=c(3,4,6,7,3))
fit = ggplot(a1, aes(x,y)) + geom_text(aes(label=Freq), size=5)+
theme_bw() +
scale_x_continuous(breaks = seq(min(a1$x)-1,max(a1$x)+1,by=1),
labels = seq(min(a1$x)-1,max(a1$x)+1,by=1),
limits = c(min(a1$x)-1,max(a1$x)+1))+
scale_y_continuous(breaks = seq(min(a1$y),max(a1$y),by=2))
Run Code Online (Sandbox Code Playgroud)
(2,4) 处的 3 个点是右删失的。我希望将它们绘制到右侧一个单位,并使用相应的 xaxis 刻度标记“>=2”而不是 3。如果可能,有什么想法吗?
这是很有可能。我破解了数据,所以2,4
它是3,4
。然后我修改了你的标签,只要它们与休息的长度相同,就可以是任何你想要的。
ggplot(a1, aes(x,y)) + geom_text(aes(label=Freq), size=5)+
theme_bw() +
scale_x_continuous(breaks = seq(min(a1$x)-1,max(a1$x),by=1),
labels = c(seq(min(a1$x)-1,max(a1$x)-1,by=1), ">=2"),
limits = c(min(a1$x)-1,max(a1$x)))+
scale_y_continuous(breaks = seq(min(a1$y),max(a1$y),by=2))
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2602 次 |
最近记录: |