I have a table with averages and interquartile ranges. I would like to create a dotplot, where the dot would show this average, and a bar would stretch through the dot, to show the interquartile range. In other words, the dot would be at the midpoint of a bar, the length of which would equal my interquartile range data. I am working in R.
For example,
labels<-c('a','b','c','d')
averages<-c(10,40,20,30)
ranges<-c(5,8,4,10)
dotchart(averages,labels=labels)
where the ranges would then be added to this plot as bars.
Any ideas?
Thanks!
Dot plot in R 1 The dotchart function. The dotchart function allows to create a Cleveland’s dot plot in R. ... 2 Dot plot by group in R. If you have a variable that categorizes the data in groups, you can separate the dot chart in that groups, setting them in the ... 3 Order dotchart in R by a variable. ... 4 Dumbbell dot plot in R. ...
How to Use Spread Function in R (With Examples) The spread () function from the tidyr package can be used to “spread” a key-value pair across multiple columns. This function uses the following basic syntax: spread (data, key value)
Note that there are several types of dot charts, like the classical, the Cleveland’s version and Dumbbell dot plots. In this tutorial we are going to show how to create Cleveland dot plots in R and Dumbbell charts.
Figure 6.31: Dot plot of multiple groups, binning along the y-axis Dot plots are sometimes overlaid on box plots. In these cases, it may be helpful to make the dots hollow and have the box plots not show outliers, since the outlier points will appear to be part of the dot plot (Figure 6.32 ):
Yet another method, using base.
labels <- c('a', 'b', 'c', 'd')
averages <- c(10, 40, 20, 30)
ranges <- c(5, 8, 4, 10)
dotchart(averages, labels=labels, xlab='average', pch=20,
xlim=c(min(averages-ranges), max(averages+ranges)))
segments(averages-ranges, 1:4, averages+ranges, 1:4)
For the record, here's a lattice solution, which uses a couple of functions from the Hmisc package:
library(lattice)
library(Hmisc)
labels<-c('a','b','c','d')
averages<-c(10,40,20,30)
ranges<-c(5,8,4,10)
low <- averages - ranges/2
high <- averages + ranges/2
d <- data.frame(labels, averages, low, high)
Dotplot(labels ~ Cbind(averages, low, high), data = d,
col = 1, # for black points
par.settings = list(plot.line = list(col = 1)), # for black bars
xlab = "Value")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With