I tried to plot a worldmap with my dataset combined but all I get is a grey worldmap or nothing at all.

I did load the necessary packages.

Codes before plotting

df <- NCD_RisC_Lancet_2017_BMI_age_standardised_country

df2 = filter(df, Year == "2016")

dfmann = filter(df2, Sex == "Men")
colnames(dfmann)[colnames(dfmann)=="Country/Region/World"] <- "Country"
colnames(dfmann)[colnames(dfmann)=="Mean BMI"] <- "Mean_BMI"
colnames(dfmann)
dfman = select(dfmann, Country, Year, Sex, Mean_BMI)

worldbmi <- map_data("world")
p <- ggplot(data = worldbmi,
            mapping = aes(x = long, y = lat,
                          group = group))
p + geom_polygon(fill = "white", color = "black")

p <- ggplot(data = worldbmi,
            aes(x = long, y = lat,
                group = group, fill = region))
p + geom_polygon(color = "gray90", size = 0.1) + guides(fill = FALSE)


dfman2$region <- tolower(dfman2$Country)
world_bmi <- left_join(worldbmi, dfman2, by = "region")
head(world_bmi)
world_bmi

codes for plotting

p1 <- ggplot(data = world_bmi,
            aes(x = long, y = lat,
                group = group, fill = Mean_BMI))
p1 + geom_polygon(color = "gray90", size = 0.1)  + 
  scale_fill_gradient(low = "white", high = "#CB454A")

p2 <- p1 + theme_map() +
  labs(fill = NULL)
p2

# I also tried this
p0 <- ggplot(data = world_bmi,
             mapping = aes(x = long, y = lat, group = group, fill = Mean_BMI))
p1 <- p0 + geom_polygon(color = "gray90", size = 0.1)
p2 <- p1 + scale_fill_gradient2() + labs(title = "BMI 2016 Men")
p2 + theme_map() + labs(fill = "BMI")

p3 <- p1 + scale_fill_gradient2(low = "red", mid = scales::muted("purple")) +
                             labs(title = "BMI 2016")
p3 + theme_map() + labs(fill = "BMI")

What is this dataset ?
It would be useful for us to help you to have a reprex we can use to reproduce

Could you ask this with a minimal REPRoducible EXample (reprex)? A reprex makes it much easier for others to understand your issue and figure out how to help.

http://www.ncdrisc.org/data-downloads-adiposity.html -> country specific data

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.