如何更改ggplot中的标签(图例)? [英] How to change labels (legends) in ggplot?
问题描述
我的代码如下所示,我想更改ggplot的标签,但R总是提醒我:
pre $ 错误单位(tic_pos.c,mm):'x'和'单位'必须有长度> 0
我该怎么办? 由于您没有提供任何数据,下面是一个使用内置 在这个例子中, 会导致与您相同的错误,因为 My code is like below, I want to change the label of the ggplot, but R always remind me: What should I do?
Is Since you did not provide any data, here's an example using the built-in In this example, would cause the same error that you are getting, because 这篇关于如何更改ggplot中的标签(图例)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
<$ p $ b $ ggplot(mat,aes(x = sales,col = type))+
geom_density()+ labels(red_sold,blue_sold,yellow_sold)
mat $ type
一个因素?如果不是,那会导致错误。此外,您不能使用标签(...)
这种方式。
mtcars
数据集的示例。
ggplot(mtcars,aes(x = hp,color = factor(cyl)))+
geom_density()+
scale_color_manual(name =Cylinders,
labels = c(4 Cylinder ,6 Cylinder,8- Cylinder),
values = c(red,green,blue))
ggplot(mtcars,aes(x = hp,color = cyl))+。 ..
mtcars $ cyl
不是一个因素。Error in unit(tic_pos.c, "mm") : 'x' and 'units' must have length > 0
ggplot(mat,aes(x=sales,col=type))+
geom_density()+labels("red_sold","blue_sold","yellow_sold")
mat$type
a factor? If not, that will cause the error. Also, you can't use labels(...)
this way.mtcars
dataset.ggplot(mtcars, aes(x=hp,color=factor(cyl)))+
geom_density()+
scale_color_manual(name="Cylinders",
labels=c("4 Cylinder","6 Cylinder","8- Cylinder"),
values=c("red","green","blue"))
ggplot(mtcars, aes(x=hp,color=cyl))+...
mtcars$cyl
is not a factor.