首页 > 解决方案 > 图形没有ggplot

问题描述

我需要帮助来制作这个图形ggplot2圆形图形

我不知道如何将月份放在 x 轴上,我也无法正确地将数据放在 y 轴上。我的数据超出规模。

我正在尝试使用此代码:

dados1 <-read.table("dados.txt", header=TRUE)

registro<-dados1$Registro

ggplot(dados1, aes(x = registro)) +
 geom_histogram(colour="black", breaks = seq(0,12), closed="left") + 
 labs (title = "RS030", subtitle = "") +
 coord_polar(theta="x",start=0, direction = 1) + 

scale_x_continuous(name="",limits=c(0,12),breaks=0:12, labels=0:12, position = "bottom")+ 

 scale_y_continuous(name="", limits = c(0,16),breaks= seq(0,16,by=4),
                 labels =seq(0,16,by=4), position = "right")+

 theme_minimal()+
 theme(plot.title=element_text(size=14), plot.subtitle=element_text(size=10),
    panel.grid = element_line(colour="gray", linetype=1, size=0),
    panel.grid.major.x = element_line(colour="gray", linetype=1, size=0),
    panel.background = element_rect(colour="white", fill="white"),
    text=element_text(size=11),
    axis.text.x = element_text(face="bold", color="black",size=10),
    axis.text.y = element_blank())+

annotate("text",label = seq(0,16,4),
     x = 12, y=seq(0,16,4),
     color="black", size=3, 
     fontface="plain",hjust=1,vjust=1)

标签: rggplot2graphics

解决方案


如果可能,请提供数据集,因此关键是将您的月份或列设置为一个因子,使用 geom_bar() 来计算因子(比使用直方图好得多)然后您需要引入将您的限制设置为 -ve值,以便酒吧会向上推..你可以尝试这样的事情来开始:

library(ggplot2)
set.seed(111)
dados1 = data.frame(Registro=sample(1:12,100,replace=TRUE))
YLIM = max(table(dados1$Registro))

ggplot(dados1, aes(x = factor(Registro))) +
 geom_bar(colour="black",stat="count",width=0.5,fill="#00bcd4") + 
 ylim(c(-YLIM/2,YLIM))+
 labs (title = "RS030", subtitle = "") +
 coord_polar(theta="x",start=0, direction = 1) + 
scale_x_discrete(name="",breaks=1:12, 
labels=month.abb, position = "bottom")+
theme_bw()

在此处输入图像描述


推荐阅读