我正在尝试在ggplot2中创建一个图。以下是名为problem_accept_df的数据:
Order Application probscore
1 Integrated 0.8333333
1 Tabbed 0.7777778
2 Integrated 0.8965517
2 Tabbed 0.7777778
3 Integrated 0.7931034
3 Tabbed 0.7777778
4 Integrated 0.7
4 Tabbed 0.6538462
5 Integrated 0.9285714
5 Tabbed 0.8333333
6 Integrated 0.9310345
6 Tabbed 0.8148148
7 Integrated 0.8571429
7 Tabbed 0.8518519
8 Integrated 0.9333333
8 Tabbed 0.6923077
9 Integrated 0.9310345
9 Tabbed 0.8461538
10 Integrated 0.9285714
10 Tabbed 0.8下面是创建该图的代码:
ggplot(problem_accept_df, aes(x=Order, y=probscore, color=Application,
group=Application)) +
xlab('Order') +
ylab('Problem scores') +
geom_line(position=pd, size=2) +
geom_point(position=pd, size=4) +
labs(title='Acceptable proportion of problem scores')将创建绘图,但y值显示在等间距的记号标记上,即使这些值不是等间距的。该图还显示每个单独的y值,而不是一个范围。我已经尝试过更改(scale_y_continuous(breaks=seq(0.5, 1, 0.1))),但是我得到了错误消息Error: Discrete value supplied to continuous scale,所以这个问题一定是更基本的。如果您有什么建议,我将不胜感激。
发布于 2012-12-12 03:41:38
当数据(在您的例子中是probscore)是一个因子而不是连续变量时,通常会发生这种情况。
> d <- data.frame(x=c(0,1), y=factor(c(0.5, 1.5)))
> d
x y
1 0 0.5
2 1 1.5
> levels(d$x)
NULL
> levels(d$y)
[1] "0.5" "1.5"
> library(ggplot2)
> ggplot(d, aes(x=x, y=y)) + geom_point() + scale_y_continuous()
Error: Discrete value supplied to continuous scale
> ggplot(d, aes(x=x, y=as.numeric(as.character(y)))) + geom_point() + scale_y_continuous()https://stackoverflow.com/questions/13827098
复制相似问题