[英]ggplot2 issue with y axis
我有以下均值表:
Sex Trait Average
1 1 -N 9.042735
2 2 -N 3.529577
3 1 E 8.111111
4 2 E 9.447887
5 1 O 17.196580
6 2 O 16.311800
7 1 A 12.213680
8 2 A 13.449440
9 1 C 12.025640
10 2 C 14.529580
从这里运行以下图形:
library(ggplot2)
plot <- ggplot(meansMatrix, aes(Trait, Average, colour= Sex,group= Sex)) +
geom_line(aes(linetype=Sex),size=1) +
geom_point(size=3,fill="white") +
scale_color_manual(values = c("black", "grey50")) +
scale_y_discrete(limits=c(0,18),breaks=seq(2,18,2.5),labels=seq(2,18,2.5)) +
scale_x_discrete(limits=c("-N","E","O","A","C")); plot
y轴存在问题。 将变量“ Average
设置为数值后,我尝试通过更改参数( limits, breaks
和labels
)进行不同的组合,但均未成功。 除了错误消息外,这是唯一弹出的图形。
非常感谢您输入任何有关如何重新定位图并显示相应中断的信息!
使用scale_y_continuous
:
meansMatrix <- read.table(text=" Sex Trait Average
1 1 -N 9.042735
2 2 -N 3.529577
3 1 E 8.111111
4 2 E 9.447887
5 1 O 17.196580
6 2 O 16.311800
7 1 A 12.213680
8 2 A 13.449440
9 1 C 12.025640
10 2 C 14.529580", header=TRUE)
meansMatrix$Sex <- factor(meansMatrix$Sex)
library(ggplot2)
p <- ggplot(meansMatrix, aes(Trait, Average, colour= Sex,group= Sex)) +
geom_line(aes(linetype=Sex),size=1) +
geom_point(size=3,fill="white") +
scale_color_manual(values = c("black", "grey50")) +
scale_y_continuous(limits=c(0,18),breaks=seq(2,18,2.5),labels=seq(2,18,2.5)) +
scale_x_discrete(limits=c("-N","E","O","A","C"))
print(p)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.