0

I am able to create datatables, pivots, maps etc. but, cannot for the life of me create a dataset usable in Plotly for R.

In this example I keep getting and error in the last element ending with 'object 'prem_council' not found

My code is:

#### DATA ##
lic1 <- tbl(con, "ca_licenses") %>% 
  select(type,license,lic_app,status,master,prem_city_ps,class_parent,prem_council,prem_neighborhood) %>%
    filter(prem_city_ps == "LOS ANGELES", lic_app == "LIC", status == "ACTIVE", master == "Y") %>%
      collect()

lic2 <- tbl_df(lic1) 

lic3 <- as_tibble(cbind(nms = names(lic2), t(lic2)))

plot_ly(lic3, x = prem_council, y = type, type = "bar")

I removed my comments so I don't appear as a complete donk. My question is what exactly are the steps for taking a typical dataset of row/column data and preparing it to create Plotly charts? My steps are:

lic1 <- collecting/filtering/selecting the data from a postgres table (works great), lic2 <- creating a dataframe lic3 <- creating a tibble by transposing data and where first col is now the names (nms) column And lastly creating the chart.

Image illustrates the output from lic3

I have used rm(list=ls()) to flush the memory as I've tried many different things.

Loaded libraries include RPostgreSQL, DBI, dbplyr, dplyr, plotly

Any insight would be appreciated! New to R and can't wait to get this down. Thanks.

zx8754
  • 52,746
  • 12
  • 114
  • 209
civarchive
  • 67
  • 11
  • Are you trying to fix an error or is this code already working? – javad Nov 27 '17 at 23:59
  • I'm trying to fix the error. This is the complete message: Error in plot_ly(lic3, x = prem_council, y = type, type = "bar") : object 'prem_council' not found – civarchive Nov 28 '17 at 01:30

1 Answers1

0

When you write prem_council, R is looking for that object in the workspace, not in the tibble you have created, therefore it cannot find it. Try this instead

plot_ly(lic3, x = ~prem_council, y = ~type, type = "bar")
javad
  • 498
  • 4
  • 15
  • Thanks Javad. I tried that as well and when I tried just not, I get this error: 'Error in eval(expr, data, expr_env) : object 'prem_council' not found'. – civarchive Nov 29 '17 at 04:10
  • It is hard to say because I don't see the data. When you examine lic3, does it have the perm_council field? – javad Nov 29 '17 at 11:59