I've searched both S.O. & Google for this. There are lots of answers, but I can't really seem to find one that's helping me pin down the actual problem I'm having.
Here's my code:
library(RNeo4j)
library(tidyverse)
library(stringr)
library(MASS)
### uncomment the next 2 lines to reconnect to server & re-query the database
# setwd("~/Desktop/Dashrock/Neo4j")
# source("N4j_connect_query.R")
df <- naics_jll %>%
group_by(m.mkt,c1.name) %>%
summarize(n1_4_pct =sum(n.n1_4)/sum(n.est),
n5_9_pct =sum(n.n5_9)/sum(n.est),
n10_19_pct =sum(n.n10_19)/sum(n.est),
n20_49_pct =sum(n.n20_49)/sum(n.est),
n50_99_pct =sum(n.n50_99)/sum(n.est),
n100_249_pct =sum(n.n100_249)/sum(n.est),
n250_499_pct =sum(n.n250_499)/sum(n.est),
n500_999_pct =sum(n.n500_999)/sum(n.est),
n1000_pct =sum(n.n1000)/sum(n.est),
n1000_1_pct =sum(n.n1000_1)/sum(n.est),
n1000_2_pct =sum(n.n1000_2)/sum(n.est),
n1000_3_pct =sum(n.n1000_3)/sum(n.est),
n1000_4_pct =sum(n.n1000_4)/sum(n.est),
ap = sum(n.ap),
emp = sum(n.emp),
num_firms = sum(n.est))
g <- ggplot(df)
g +
geom_point(aes(x=c1.name, y=n100_249_pct, color = factor(m.mkt)), na.rm = TRUE) +
facet_grid(. ~ m.mkt) +
labs(x = "Industry Code (NAICS)", y = "Btwn 100-249 Employees (as % of All Companies)", title = "Company Profiles") +
theme(axis.text.x = element_text(angle=90, hjust = .5, vjust=.5, size=5))
This works just fine. Here's the output:
The problem is, when I change from geom_point
to geom_bar
(which is what I really want), I get different versions of this error:
Error in factor(n100_249_pct) : object 'n100_249_pct' not found
What's wrong?