p <- ggplot ( pokemon, aes ( x = `Max HP`, y = `Max CP` )) + geom_smooth ( data = pokemon, method = "lm", se = FALSE, col = "#ee1515" ) + geom_point ( aes ( col = type_1 )) + # Arrow for pokemon Chansey geom_curve ( aes ( x = 375, y = 1500, xend = 404, yend = 860 ), colour = "#555555", curvature = -.2, size =. Let’s add annotations to display this extra information on the chart. What’s next? Iteration 7 - Add annotationsĪnd who’s that guy on the far right that seems to be so weak and have so many HPs? ![]() Note that I don’t need anymore to reduce the font size of the legend.Īnd I forced the legend to be displayed on 1 row so that we have more place for the actual chart. Let’s adapt our chart code and see what happens: p <- ggplot ( pokemon, aes ( x = `Max HP`, y = `Max CP` )) + geom_smooth ( data = pokemon, method = "lm", se = FALSE, col = "#ee1515" ) + geom_point ( aes ( col = type_1 )) + # Title labs ( title = "Relationship between Max CP and Max HP" ) + # Axis scale_x_continuous ( labels = function ( x ) paste0 ( x, " HP" )) + scale_y_continuous ( labels = function ( y ) paste0 ( y, " CP" )) + # Legend scale_color_manual ( values = colors, guide = guide_legend ( nrow = 1 )) + # Style bbc_style () + theme ( plot.title = element_text ( color = "#063376" )) ![]() I also reordered the factors to make sure that “Other” finds itself in last position (rather than by alphabetical order). ![]() I will use the PokemonGO dataset that has been uploaded by Alberto Barradas on Kaggle: library ( data.table ) pokemon = 10, `Type 1`, "Other" )] pokemon sort ( table ( pokemon $ type_1 )) # Bug Fire Grass Poison Normal Water Other # 12 12 12 14 22 28 51 To follow along with this article, let’s generate some data so that we’re all on the same page. You’ll soon be ready to create your own infographics with R!
0 Comments
Leave a Reply. |