Watts-College / cpp-529-spr-2022

https://watts-college.github.io/cpp-529-spr-2022/
0 stars 2 forks source link

Lab 04 Error: Fill argument neither colors nor valid variable name(s) #16

Closed ebossert closed 2 years ago

ebossert commented 2 years ago

I get the titled error when I run the code chunk below. I've googled it but I'm still unclear on what is causing the error. All I changed is the first line for my city dorling, and the error refers to the last line of tmap_arrange. When I remove the tmap_arrange line it returns this:

tmap mode set to plotting tmap style set to "cobalt" other available styles are: "white", "gray", "natural", "col_blind", "albatross", "beaver", "bw", "classic", "watercolor"

det_dorling$cluster3 <- as.factor( fit3$classification )

tmap_mode("plot")
tmap_style("cobalt")

tm1 <- 
tm_shape( det_dorling, bbox=bb ) + 
  tm_polygons( col="cluster", palette="Spectral"  )

tm2 <- 
tm_shape( det_dorling, bbox=bb ) + 
  tm_polygons( col="cluster2", palette="Spectral"  )

tm3 <- 
tm_shape( det_dorling, bbox=bb ) + 
  tm_polygons( col="cluster3", palette="Spectral"  )

tmap_arrange( tm1, tm2, tm3 )

Error: Fill argument neither colors nor valid variable name(s)

JasonSills commented 2 years ago

Hi @ebossert ,

Let's check previous code chunks. In the code chunks prior to this did you run code for "cluster" and "cluster2"? You have a line of code in this chunk for det_dorling$cluster3 <- as.factor( fit3$classification ). Check your code chunks prior to this and make sure you have both:

det_dorling$cluster <- as.factor( fit$classification )

and

det_dorling$cluster2 <- as.factor( fit2$classification )

ebossert commented 2 years ago

@JasonSills Thank you!

This was totally user error. I skipped running the code chunk with det_dorling$cluster <- as.factor( fit$classification ) because it takes so long and didn't even think about the potential consequences. Not doing that again!

novalabdl commented 1 year ago

Hi @ebossert ,

Let's check previous code chunks. In the code chunks prior to this did you run code for "cluster" and "cluster2"? You have a line of code in this chunk for det_dorling$cluster3 <- as.factor( fit3$classification ). Check your code chunks prior to this and make sure you have both:

det_dorling$cluster <- as.factor( fit$classification )

and

det_dorling$cluster2 <- as.factor( fit2$classification )

hey sir i have the same problem,can you help me?

this is my script legend_title = expression("Fixed: Local R2") map_fbgwr1 = tm_shape(Krucil_shp1, bbox = bbox_new)+ tm_fill(col = "fmb__localR2", title = legend_title, palette = magma(256), style = "cont")+ tm_borders(col = "white", lwd= .1)+ tm_compass(type = "arrow", position = c("left","top"), size = 3) + tm_scale_bar(breaks = c(0,1,2), text.size = 0.7, position = c("left","bottom"))+ tm_layout(bg.color = "white") map_fbgwr1+tm_shape(Krucil_shp1)+ tm_borders(col = "blue", lwd = .5)

after i run tm_borders this come up Error: Fill argument neither colors nor valid variable name(s)