I am new to R and am using lattice to create a clustered bar graph. I wrote the following code.
nature <- read.table(text = "Nature_of_recreation, Familiarity_with_the_partner, Count
Danced, Not familiar at all, 21
Danced, Not very familiar, 22
Danced, Very familiar, 22
Sketched, Not familiar at all, 6
Sketched, Not very familiar, 17
Sketched, Very familiar, 16
Dined, Not familiar at all, 16
Dined, Not very familiar, 14
Dined, Very familiar, 10
Swimmed, Not familiar at all, 6
Swimmed, Not very familiar, 15
Swimmed, Very familiar, 11
Played, Not familiar at all, 1
Played, Not very familiar, 6
Played, Very familiar, 7
Dreamed, Not familiar at all, 5
Dreamed, Not very familiar, 17
Dreamed, Very familiar, 10",
header = TRUE, sep = ",")
colors = c("lightsalmon3", "lightgoldenrod2", "cadetblue4")
lattice::barchart(data = nature, origin = 0, Count ~ Nature_of_recreation,
groups = Familiarity_with_the_partner,
xlab = list(label = "Nature of recreation", font = 2, cex = 1),
ylab= list (label = "Number of students", font = 2, cex = 1),
labels = TRUE, auto.key = list(space="top", columns= 3),
par.settings = list(superpose.polygon = list(col = colors)))
The output looks all good, except:
- It has a white space in between bars and the X-axis.
- It does not have values displayed on top of each bar.
Can anyone please help me fix these issues?