我有一个使用此代码的情节:
ex1 <- data.frame(Proc=rep(c("32", "16", "8", "4"), each=4),
CX=rep(c("C1", "C2", "C3", "C4"),4),
Time=c(15.58,16.94,23.25,24.11,9.6,10.09,12.32,12.95,5.72,6.11,6.87,6.85,3.51,3.54,3.54,3.54))
ggplot(ex1, aes(x=Proc, y=Time, colour=CX,
shape=CX, linetype=CX, group=CX)) +
geom_point() +
geom_line() +
theme_linedraw() +
theme(legend.position="bottom",axis.text.x = element_text(angle=45), axis.text.y = element_text(angle=0)) + coord_cartesian(ylim = c(0, 32)) +
scale_x_discrete(limits=c("4", "8", "16", "32"))
所以,我希望x轴上的数字具有成比例的空间,因为实际上16到32之间的空间在4到8之间是相同的。
我想为x轴显示:4 8 _ 16 _ _ _ 32
我尝试过:(没有成功)
scale_x_discrete(breaks=c(seq(4,32,by=4)), limits=c("4", "8", "16", "32"))
我怎样才能得到那个情节?我需要使用什么功能?
答案 0 :(得分:3)
此:
ex1 <- data.frame(Proc=rep(c("32", "16", "8", "4"), each=4),
CX=rep(c("C1", "C2", "C3", "C4"),4),
Time=c(15.58,16.94,23.25,24.11,9.6,10.09,
12.32,12.95,5.72,6.11,
6.87,6.85,3.51,3.54,3.54,3.54))
ex1$Nproc <- as.numeric(as.character((ex1$Proc)))
ggplot(ex1, aes(x=Nproc, y=Time, colour=CX,
shape=CX, linetype=CX, group=CX)) +
geom_point() +
geom_line() +
theme_linedraw() +
theme(legend.position="bottom",
axis.text.x = element_text(angle=45),
axis.text.y = element_text(angle=0)) +
coord_cartesian(ylim = c(0, 32)) +
scale_x_continuous(breaks=c(4,8,16,32),minor_breaks=NULL)
收率: