0
votes

I am trying to a barplot using R where the height of the plot is determined by the value in the second column of my dataframe, and the values in the first column of the dataframe appear as titles at the bottom on the plot.

It seems that solutions like

g <- ggplot(mpg, aes(class)) g + geom_bar()

Create a bar plot where the height is the frequency of each unique value in class

My Current solution

> data
    obj        rate smt
1 test1 0.000342500   1
2 test2 0.000508000   1
3 test3 0.000599167   1
4 test4 0.000339000   1
> g <- ggplot(data, aes(obj,rate)) + geom_col()

Return an empty pdf called Rplots.pdf

To clarify, using this code I would like one PDF where the values on the bottom are "test1 test2 test3 test4" which reach heights of 0.000342500, 0.000508000, 0.000599167, and 0.000339000 respectively. There should be four bars in this plot.

1

1 Answers

1
votes

If you are only concerned with plotting to pdf

library(ggplot2)
data <- structure(list(obj = structure(1:4, .Label = c("test1", "test2", "test3", "test4"), class = "factor"), rate = c(0.0003425, 0.000508, 0.000599167, 0.000339), smt = c(1, 1, 1, 1)), .Names = c("obj", "rate", "smt"), row.names = c(NA, -4L), class = "data.frame")

pdf("Rplots.pdf")
ggplot(data, aes(obj,rate)) + geom_col()
dev.off()