Reputation: 121
How could I have the similar graph as the graph below in R.
The data set format is
Ld.L 2.5
Ld.p 2
Ap.n 0.67
Ap.m 1.5
...
Collumn 1 is variables (e.g., Ld.L) and collumns 2 is doffirences
Upvotes: 0
Views: 95
Reputation: 23574
One way would be that you want to add another column for variable
to specify position on x-axis. The following sample data has three columns.
foo <- data.frame(letters = c("Ld.L", "Ld.p", "Ap.n", "Ap.m"),
variable = c(5, 10, 7, 1),
difference = c(2.5, 2, 0.67, 1.5),
stringsAsFactors = FALSE)
# letters variable difference
#1 Ld.L 5 2.50
#2 Ld.p 10 2.00
#3 Ap.n 7 0.67
#4 Ap.m 1 1.50
If you use ggplot2
, you could do something like this.
ggplot(data= foo, aes(x = variable, y = difference, label = letters)) +
geom_text(size = 6)
If you have the names as rownames, you could do something like this.
foo2 <- data.frame(variable = c(5, 10, 7, 1),
difference = c(2.5, 2, 0.67, 1.5))
rownames(foo2) <- c("Ld.L", "Ld.p", "Ap.n", "Ap.m")
ggplot(data= foo2, aes(x = variable, y = difference, label = rownames(foo2))) +
geom_text(size = 6)
Upvotes: 2