0

What the simplest way to make a bar plot of the following data frame:

df <- data.frame(val1=10, val2=50)

I want to plot the 10 and 50 on y-axis, and val1 and val2 on x-axis correspondingly. ggplot asks for aes but since there are no row names and I want to plot column names as x-values it gives an error.

Is there an easy way to do it without modifying the dataframe itself?

danvoronov
  • 61
  • 4

1 Answers1

1

Perhaps converting df to a named vector and feeding it to barplot():

barplot(unlist(df)) 

enter image description here

s_baldur
  • 29,441
  • 4
  • 36
  • 69