0

I need help to make this graphic with ggplot2: circular graphic

I don't know how to put the months on the x-axis, and I'm also not able to put the data on the y-axis correctly. My data is out of scale.

I'm trying with this code:

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)
GGamba
  • 13,140
  • 3
  • 38
  • 47
  • 3
    Hi Ingridi, welcome to StackOverflow! Your example is not reproducible, learn how to make one here [here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). You can start by using `dput(dados1)` and adding the result to your question – GGamba Apr 06 '20 at 14:00

1 Answers1

1

If possible, please provide the dataset, so the key is to set your months or column to a factor, use geom_bar() to count the factors (much better than using a histogram) then lastly you need to introduce set your limit to -ve values so that the bars will push up.. you can try something like this to get going:

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()

enter image description here

StupidWolf
  • 45,075
  • 17
  • 40
  • 72