Reputation: 84
I have this data
> Social_Split
V1
Facebook 220
Instagram 213
Linkedin 73
None 3
Quora 44
Reddit 116
Signal 10
Snapchat 104
TikTok 88
Twitter 129
> str(Social_Split)
'data.frame': 10 obs. of 1 variable:
$ V1: num 220 213 73 3 44 116 10 104 88 129
I'm trying to plot a simple horizental barplot using ggplot so I wrote this code
gg_barplot <- ggplot(df=Social_Split, aes(x=Social_Split$V1))+
geom_bar("bin")
gg_barplot+coord_flip()
but I get this error
Error: `data` must be a data frame, or other object coercible by `fortify()`, not an S3 object with class uneval
Did you accidentally pass `aes()` to the `data` argument?
Upvotes: 2
Views: 1968
Reputation: 887501
We need to specify the column name as unquoted
library(dplyr)
library(ggplot2)
Social_Split %>%
rownames_to_column('rn') %>%
ggplot(aes(x = rn, y = V1)) +
geom_col()
Or use barplot
from base R
barplot(t(Social_Split))
Social_Split <- structure(list(V1 = c(220L, 213L, 73L, 3L, 44L, 116L, 10L, 104L,
88L, 129L)), class = "data.frame", row.names = c("Facebook",
"Instagram", "Linkedin", "None", "Quora", "Reddit", "Signal",
"Snapchat", "TikTok", "Twitter"))
Upvotes: 1