首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Graphic no ggplot

Graphic no ggplot
EN

Stack Overflow用户
提问于 2020-04-06 21:40:57
回答 1查看 41关注 0票数 0

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

我不知道如何将月份放在x轴上,也不能正确地将数据放在y轴上。我的数据大小不一。

我正在尝试使用以下代码:

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

发布于 2020-04-07 05:53:22

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

代码语言:javascript
复制
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()

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61061202

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档