0
votes

I am having a little bit of trouble inserting labels on a bar chart in ggplot2.

So far, I have been able to create the bar chart.

Pizza_bar <- ggplot(Pizza_Data_Research_Rockstar, aes(Number_of_times_eaten_pizza))
Times_eaten_pizza_7_days_bar <- Pizza_bar + geom_bar()
Times_eaten_pizza_7_days_bar

Don't know how to automatically pick scale for object of type tbl_df/tbl/data.frame. Defaulting to continuous.

The challenge becomes labeling the count of the different categories. Since I am newbie at R, I went searching for code examples but keep getting error messages.

ggplot(Pizza_Data_Research_Rockstar, aes(x= Number_of_times_eaten_pizza, y = count))+ 
geom_bar(stat = "identity", fill = "steelblue") + 
geom_text(aes(label=count), vjust=-0.3, size=3.5) + 
theme_minimal()

Don't know how to automatically pick scale for object of type tbl_df/tbl/data.frame. Defaulting to continuous. Don't know how to automatically pick scale for object of type function. Defaulting to continuous. Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, : arguments imply differing number of rows: 46, 0

That is the closest that I have gotten to adding labels.

Could someone please help? Thank you.

Luis

1
can you post some parts of your data?AK88
I am willing to do that. however, I don't see an upload button here. could you tell me how I could post the data?Luis
Ok, so i got the labels to work. However, my y-axis is out of whack.Luis
Here are my data and code. I appreciate any help.Luis
You can copy/paste first 5-10 rows of your data.AK88

1 Answers

0
votes

I really could't understand your data, so I made up my own:

Days = c("Monday", "Tuesday", "Thursday", "Friday")
Pizzas = c(40, 50, 10, 25)
Pizzadf = as.data.frame(cbind(Days, Pizzas))
Pizzadf$Pizzas = as.numeric(as.character(Pizzadf$Pizzas))

Pizzadf

ggplot(data = Pizzadf, aes(x = Days, y = Pizzas))+ 
  geom_bar(stat = "identity", fill = "steelblue") + 
  geom_text(aes(label=Pizzas), vjust=-0.3, size=3.5) + 
  theme_minimal()

Try to modify and adjust.