Kat*_*rth 13 r scatter colors scatter-plot ggplot2
我正在尝试使用以下代码在此处(sthda.com)复制示例:
# Change point shapes and colors manually
ggplot(mtcars, aes(x=wt, y=mpg, color=cyl, shape=cyl)) +
geom_point() +
geom_smooth(method=lm, se=FALSE, fullrange=TRUE)+
scale_shape_manual(values=c(3, 16, 17))+
scale_color_manual(values=c('#999999','#E69F00', '#56B4E9'))+
theme(legend.position="top")
Run Code Online (Sandbox Code Playgroud)
该网页上的示例说该代码应产生以下结果:

但是,当我在R中运行它时,出现以下错误:
“错误:连续值提供给离散刻度”
有人知道这段代码可能出什么问题吗?还是为什么我得到的结果与示例不同?
如果有人可以运行示例代码并告诉我他们是否遇到相同的错误,我将不胜感激。
Jon*_*ill 14
是的,我可以使用以下代码段对其进行修复:
ggplot(mtcars, aes(x=wt, y=mpg, color=as.factor(cyl), shape=as.factor(cyl))) +
geom_point() +
geom_smooth(method=lm, se=FALSE, fullrange=TRUE)+
scale_shape_manual(values=c(3, 16, 17))+
scale_color_manual(values=c('#999999','#E69F00', '#56B4E9'))+
theme(legend.position="top")
Run Code Online (Sandbox Code Playgroud)
as.factor使它起作用
ggplot(mtcars, aes(x=wt, y=mpg, color=as.factor(cyl), shape=as.factor(cyl))) +
geom_point() +
geom_smooth(method=lm, se=FALSE, fullrange=TRUE)+
scale_shape_manual(values=c(3, 16, 17))+
scale_color_manual(values=c('#999999','#E69F00', '#56B4E9'))+
theme(legend.position="top")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
31808 次 |
| 最近记录: |