I wrote this function to plot the city and income. The plotting code works perfectly fine when it is not inside the function. However, when I called it with the function, no graph showed up. Please help! Thanks.
graph <- function(x, y) {
df %>%
filter(city == "x", year == y) %>%
ggplot(aes(log(income)))
geom_histogram()
}
I tried to assign the plot to p
and then add print(p)
, but nothing showed up.
CodePudding user response:
you take x as a param, but dont use it in your function; you use a hardcoded x to check against city; its likely you get nothing, and so plot empty charts
besides from that, I can set up an analogous construction and see charts just fine; so theres not inherent reason that the plot wouldnt be seen from inside a function like this