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")