Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.6玫瑰图绘制的R代码会报错,请问怎么解决呢 #7

Open
dsfefgffd opened this issue Oct 21, 2022 · 2 comments
Open

3.6玫瑰图绘制的R代码会报错,请问怎么解决呢 #7

dsfefgffd opened this issue Oct 21, 2022 · 2 comments

Comments

@dsfefgffd
Copy link

mydata <- data.frame( a=c("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"),
b=c(50, 60, 70, 20,90,110,30))
myAngle <-seq(-20,-340,length.out =7)
ggplot(mydata) +
geom_bar(aes(x=a, y=b),width = 1,stat="identity",
colour = "black",fill="#F8766D") +
geom_text(aes(x=a,y = b-8,label = b),color="white") +
coord_polar(theta = "x",start=0) +
ylim(c(0,120))+
theme_light()+
theme( panel.background = element_blank(),
panel.grid.major = element_line(colour = "grey80",size=.25),
axis.text.y = element_text(size = 12,colour="black"),
axis.line.y = element_line(size=0.25),
axis.text.x=element_text(size = 13,colour="black",angle = myAngle))

Error in if (0 <= angle & angle < 90) { : the condition has length > 1
In addition: The warning message:
Vectorized input to element_text() is not officially supported.
ℹ Results may be unexpected or may change in future versions of ggplot2.

@IvanYan2018
Copy link

可以用geom_text(aes(x=a,y = 120,label = a,angle = myAngle),color="black",size = 5) 替换x轴坐标标签,还需要隐去原来的x轴标签显示。
……
ggplot(mydata) +
geom_bar(aes(x=a, y=b),width = 1,stat="identity",
colour = "black",fill="#F8766D") +
geom_text(aes(x=a,y = b-8,label = b,angle = myAngle),color="white") +
geom_text(aes(x=a,y = 120,label = a,angle = myAngle),color="black",size = 5) +
coord_polar(theta = "x",start=0) +
ylim(c(0,120))+
theme_light()+
theme( panel.background = element_blank(),
panel.grid.major = element_line(colour = "grey80",size=.25),
axis.text.y = element_text(size = 12,colour="black"),
axis.line.y = element_line(size=0.25),
axis.text.x = element_blank())
……

@chenwenqi228
Copy link

问题主要出在最后一行angle=myAngle(Monday这些标签旋转角度),把myAngle换成数字就可以了。我的命令改成:
ggplot(mydata) +
geom_bar(aes(x=a, y=b),width = 1,stat="identity",
colour = "black",fill="#F8766D") +
geom_text(aes(x=a,y = b-8,label = b),color="white") +
coord_polar(theta = "x",start=0) +
ylim(c(0,120))+
theme_light()+
theme( panel.background = element_blank(),
panel.grid.major = element_line(colour = "grey80",size=.25),
axis.text.y = element_text(size = 12,colour="black"),
axis.line.y = element_line(size=0.25),
axis.text.x=element_text(size = 10,colour="black",angle = 0)) #字号缩小一点,标签水平放置
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants