r - 图形没有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)
解决方案
如果可能,请提供数据集,因此关键是将您的月份或列设置为一个因子,使用 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()
推荐阅读
- mongodb - 如何使用 Mongoose 以随机顺序返回结果(使用跳过、限制)
- python - 从 ImageGrab 中定位黑色像素的位置
- python - 在Python中查找列表列表中第一个元素的总和
- oracle - os 内核参数缺少 semmni
- regex - 在句子中给出全名,除了具有该全名的句子之外,有没有办法匹配任何内容?
- nsis - 如何在 nsis 中仅使用 unicode?
- sql - 如何使用 sql server proc 在 7 天前通知用户许可证将在 7 天内到期
- javascript - Javascript 将 1970 年 1 月 1 日转换为 1970 年 1 月 1 日
- c# - 从一个字符读取字符串到另一个字符
- bash - 按功能测试 bash 脚本功能