Create a demo dataset to be used for a plot.
# Sample data
set.seed(3)
sold <- sample(200:500, 12)
sold
## [1] 460 385 339 235 499 475 382 367 247 303 335 236
month <- month.name
month
## [1] "January" "February" "March" "April" "May" "June"
## [7] "July" "August" "September" "October" "November" "December"
quarter <- c(rep(1, 3), rep(2, 3),
rep(3, 3), rep(4, 3))
quarter
## [1] 1 1 1 2 2 2 3 3 3 4 4 4
# Sample dataSet
df <- data.frame(sold, month,quarter)
df
## sold month quarter
## 1 460 January 1
## 2 385 February 1
## 3 339 March 1
## 4 235 April 2
## 5 499 May 2
## 6 475 June 2
## 7 382 July 3
## 8 367 August 3
## 9 247 September 3
## 10 303 October 4
## 11 335 November 4
## 12 236 December 4
dotchart(df$sold,
pch = 17,
pt.cex = 1.5,
labels = month,
groups = rev(quarter)
)
# Colors for each group
cols <- c(rep("#56B4E6", 3), rep("#009E73", 3),
rep("#0072B2", 3), rep("#D55E00", 3))
dotchart(sold,
pch = 19,
pt.cex = 1.5,
labels = month,
groups = rev(quarter),
color = cols,
gcolor = 1
)
# Colors for each group
cols <- c(rep("#56B4E9", 3), rep("#009E73", 3),
rep("#0072B2", 3), rep("#D55E00", 3))
dotchart(sold,
pch = 19, pt.cex = 1.5,
labels = month,
groups = rev(quarter),
color = cols,
gdata = rev(tapply(sold, quarter, mean)),
gpch = 12,
gcolor = 1)