全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
20815 6
2012-01-27
悬赏 20 个论坛币 已解决
操作如下:
library(ggplot2)
qplot(color,data=diamonds,geom="bar",weight=carat) +scale_y_continuous("carat")
得下图:
bar.bmp
如果把其中相对应的参数改为:scale_x_continuous,则提示错误。请问二者有什么区别?

最佳答案

qoiqpwqr 查看完整内容

因为你的x轴不是continuous的变量,y轴是。 qplot(color,data=diamonds,geom="bar",weight=carat) + scale_x_discrete("Color")
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2012-1-27 22:28:00
因为你的x轴不是continuous的变量,y轴是。
qplot(color,data=diamonds,geom="bar",weight=carat) + scale_x_discrete("Color")
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-1-28 10:41:57
如果楼主想改坐标轴的标题的话,可以这样写:
qplot(color,data=diamonds,geom="bar",weight=carat) +labs(y="克拉",x="颜色")
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-1-28 11:38:37
好像是起到修饰图形的作用,详细的用法是
scale_y_continuous(name=NULL, limits=NULL, breaks=NULL, labels=NULL, trans=NULL, expand=c(0.05, 0), minor_breaks=NULL, formatter="scientific", ...)
name: name of scale to appear in legend or on axis. Maybe be an expression: see ?plotmath
limits: numeric vector of length 2, giving the extent of the scale
breaks: numeric vector indicating where breaks should lie
labels: character vector giving labels associated with breaks
trans: a transformer to use
expand: numeric vector of length 2, giving multiplicative and additive expansion factors
minor_breaks: NULL
formatter: NULL
...: ignored


比如
(m <- qplot(rating, votes, data=subset(movies, votes > 1000), na.rm = T))
m + scale_y_continuous(limits=c(0, 5000))
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-1-28 11:39:08
qoiqpwqr 发表于 2012-1-27 23:32
因为你的x轴不是continuous的变量,y轴是。
qplot(color,data=diamonds,geom="bar",weight=carat) + scale ...
老兄,这样好像不行,我做的结果是简单的条图,也就是说,纵轴仍是count,而不是目标的carat
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-1-28 11:42:30
那你就用
qplot(color, data = diamonds, geom = "bar")+scale_y_continuous("count")
或者
qplot(color, data = diamonds, geom = "bar")
即可!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群