在x轴上显示点图的计数 [英] showing count on x-axis for dot plot
本文介绍了在x轴上显示点图的计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要一个点图,该图在x轴上显示计数.如何获得下面的点图以显示x-asax上的计数?
谢谢.
date = seq(as.Date("2016/1/5"),as.Date("2016/1/11"),"day")值= c(11,11,12,12,13,14,14)dat = data.frame(日期=日期,值=值)达特库(ggplot2)库(ggplot2)ggplot(dat,aes(x =值))+ geom_dotplot(binwidth = .8)+scale_y_discrete(breaks = seq(1,max(table(dat $ value))+ 2,1),labels = seq(1,max(table(dat $ value))+ 2,1))#使用scale_y离散变量进行尝试,但没有任何作用
解决方案
ylim(0,A)
提供所需的内容,其中A是计算1.00密度所需的堆叠点数.我们可以计算出A的确切值(但有点复杂;通过逻辑方法可以得出近似值).(我引用
I'd like to have a dot plot that shows the count on the x-axis. How can you get the dotplot below to show the count on the x-asix?
Thank you.
date = seq(as.Date("2016/1/5"), as.Date("2016/1/11"), "day")
value = c(11,11,12,12,13,14,14)
dat =data.frame(date = date, value = value)
dat
library(ggplot2)
library(ggplot2)
ggplot(dat, aes(x = value)) + geom_dotplot(binwidth = .8) +
scale_y_discrete(breaks= seq(1,max(table(dat$value))+2,1),
labels = seq(1,max(table(dat$value))+2,1) ) #tried using scale_y discrete but it does nothing
解决方案
ylim(0, A)
gives what you want, where A is the number of stacked dots necessary to count 1.00 density. We can calculate the exact value of A (but a little complexly ; Dialogical approach gives you approximate value).
(I reffered to post1, post2, and post3)
library(ggplot2); library(grid)
date = seq(as.Date("2016/1/5"), as.Date("2016/1/12"), "day")
value = c(11,11,12,12,13,14,14,14)
dat =data.frame(date = date, value = value)
### base plot
g <- ggplot(dat, aes(x = value)) + geom_dotplot(binwidth = 0.8) + coord_flip()
g # output to read parameter
### calculation of width and height of panel
grid.ls(view=TRUE,grob=FALSE)
seekViewport('panel.3-4-3-4')
real_width <- convertWidth(unit(1,'npc'), 'inch', TRUE)
real_height <- convertHeight(unit(1,'npc'), 'inch', TRUE)
### calculation of other values
height_coordinate_range <- diff(ggplot_build(g)$panel$ranges[[1]]$y.range)
real_binwidth <- real_height / height_coordinate_range * 0.8 # 0.8 is the argument binwidth
num_balls <- real_width / 1.1 / real_binwidth # the number of stacked balls. 1.1 is expanding value.
g + ylim(0, num_balls)
# The dirty balls border probably comes from my environment.
这篇关于在x轴上显示点图的计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文