0

Im working on heatmaps for New Jersey population, the dataset is called "NJ" and it has a column called "Population". I want to define the color buckets for the range of population. However, when I use the code given below, it always gives me an error of : Error in NJ$Population : $ operator is invalid for atomic vectors

 NJpalette<-brewer.pal(7,"Blues")
 NJ$colorBuckets<-as.numeric(cut(NJ$Population,c(0,150000,30000,450000,600000,750000,900000,1000000)))

I dont unerstand why it happens, I read that instead of using $ I could call population using

NJ[Population]

However, even that doesnt help. Can someone please suggest how to go forward

Mannat M
  • 167
  • 1
  • 3
  • 11
  • `NJ<-brewer.pal(7,"Blues")# Error: could not find function "brewer.pal"` Please do update with the package that has the relevant function. – akrun Mar 25 '15 at 13:11
  • 2
    I assume it is from `RColorBrewer`. Check the `str(NJ)`. It is a character vector. `str(NJ)# chr [1:7] "#EFF3FF" "#C6DBEF" "#9ECAE1" "#6BAED6" "#4292C6" ...` No idea how you got `NJ$Population` that doesn't exist in `NJ` or at least not shown in your code. – akrun Mar 25 '15 at 13:21
  • possible duplicate of [Why doesn't R allow $ operator on atomic vectors?](http://stackoverflow.com/questions/9824268/why-doesnt-r-allow-operator-on-atomic-vectors) – Carl Witthoft Mar 25 '15 at 13:44
  • @akrun i have update my question, NJ is the df and Population is a column in it – Mannat M Mar 25 '15 at 16:12
  • 1
    @Swarnalakshmi If that is the case, please do show the code in the post to make it reproducible. The thing that changed is `NJ` became `NJpalette`. The reason we ask for providing reproducible code is to solve your problem more quickly rather than guessing what might be the problem. – akrun Mar 25 '15 at 16:14
  • http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – akrun Mar 25 '15 at 16:22
  • @akrun thanks akrun, I resolved it. Careless mistake! Thanks for correcting :) – Mannat M Mar 29 '15 at 04:43

0 Answers0