Reputation: 65
I have this dataset and I want to draw a dotplot out of it (not with ggplot functions).
species measurement test ref log
1 asinus 1 73.6 76.6 -0.03995205
2 asinus 2 67.1 69.9 -0.04088161
3 asinus 3 24.5 24.8 -0.01217054
4 asinus 4 39.8 41.1 -0.03214121
5 asinus 5 29.0 31.0 -0.06669137
6 caballus 1 79.8 76.6 0.04092643
7 caballus 2 71.7 69.9 0.02542510
8 caballus 3 33.4 24.8 0.29771225
9 caballus 4 52.9 41.1 0.25239522
10 caballus 5 34.7 31.0 0.11275248
11 grevy 1 85.5 76.6 0.10991930
12 grevy 2 78.9 69.9 0.12111558
13 grevy 3 30.2 24.8 0.19699827
14 grevy 4 50.2 41.1 0.20000691
15 grevy 5 35.0 31.0 0.12136086
16 kiang 1 85.0 76.6 0.10405418
17 kiang 2 79.4 69.9 0.12743272
18 kiang 3 25.9 24.8 0.04339932
19 kiang 4 43.7 41.1 0.06133998
20 kiang 5 32.1 31.0 0.03486883
structure(list(species = c("asinus", "asinus", "asinus", "asinus",
"asinus", "caballus", "caballus", "caballus", "caballus", "caballus",
"grevy", "grevy", "grevy", "grevy", "grevy", "kiang", "kiang",
"kiang", "kiang", "kiang"), measurement = c(1L, 2L, 3L, 4L, 5L,
1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L),
test = c(73.6, 67.1, 24.5, 39.8, 29, 79.8, 71.7, 33.4, 52.9,
34.7, 85.5, 78.9, 30.2, 50.2, 35, 85, 79.4, 25.9, 43.7, 32.1
), ref = c(76.6, 69.9, 24.8, 41.1, 31, 76.6, 69.9, 24.8,
41.1, 31, 76.6, 69.9, 24.8, 41.1, 31, 76.6, 69.9, 24.8, 41.1,
31), log = c(-0.0399520510117144, -0.0408816052621281, -0.0121705356202551,
-0.0321412092117974, -0.0666913744986721, 0.0409264277092181,
0.0254250983658109, 0.297712246811718, 0.252395217362064,
0.112752482467667, 0.10991929919617, 0.121115578612065, 0.196998271209887,
0.200006905195494, 0.121360857004267, 0.104054179743772,
0.127432719013326, 0.0433993155345553, 0.0613399805993553,
0.0348688256508241)), class = "data.frame", row.names = c(NA,
-20L))
I used this command:
dotplot (measurement ~ log)
I have two questions:
I want to change the x and y axes means that I want that the code appears in x and log appears in y axis.
I want to color code the dots based upon the species column.
I want to connect the dots that belong to a single species.
Upvotes: 1
Views: 99
Reputation: 65
I found the answer to my third question and I wish to share it with people who may have the same question.
library(lattice)
dotplot(log ~ measurement,
data = df,
groups = species,
horizontal = FALSE,
type = c("p", "l"))
I could connect the dots using "type" and define both p for points and l for lines.
Upvotes: 1
Reputation: 3294
One option would be to use dotchart
.
sps = as.factor(df$species)
sps_colors = c("red", "blue", "green", "magenta")
dotchart(df$measurement,
labels = round(df$log, 2),
color = sps_colors[sps],
groups = sps,
xlab = "measurement",
ylab = "log", pch = 19)
legend(x = "topright",
legend = unique(sps),
pch = 19, col = sps_colors[unique(sps)])
Upvotes: 1
Reputation: 16978
To answer your first two questions:
library(lattice)
dotplot(log ~ measurement,
data = df,
groups = species,
horizontal = FALSE)
should return
I actually don't know how to connect the dots...
Upvotes: 1