我有以下表格:
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
)尝试了不同的组合,但没有成功。这是除了错误消息之外弹出的唯一图形。
任何有关如何重新定位情节并显示相应休息的输入都将受到高度赞赏!
答案 0 :(得分:3)
使用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)