I’m having problems making a barplot using ggplot.
I tried different combinations of qplot and gplot, but I either get a histogram, or it swaps my bars or it decides to use log-scaling.
Using the ordinary plot functions. I would do it like:
d <- 1/(10:1)
names(d) <- paste("id", 1:10)
barplot(d)
To plot a bar chart in ggplot2, you have to use
geom="bar"orgeom_bar. Have you tried any of the geom_bar example on the ggplot2 website?To get your example to work, try the following:
ggplotneeds a data.frame as input. So convert your input data into a data.frame.geom_plotto create the bar chart. In this case, you probably want to tellggplotthat the data is already summarised usingstat="identity", since the default is to create a histogram.(Note that the function
barplotthat you used in your example is part of base R graphics, notggplot.)The code: