You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Activity
IvanYan2018 commentedon Sep 8, 2023
可以用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 commentedon Jan 13, 2024
问题主要出在最后一行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)) #字号缩小一点,标签水平放置