What

I will plot the national Brazillian Soccer Competion 2016 teams position per round.

Data was acquired on wikipedia. (https://pt.wikipedia.org/wiki/Desempenho_por_rodada_do_Campeonato_Brasileiro_de_Futebol_de_2016_-_S%C3%A9rie_A) Special characteres were adjusted on notepad++

The Data

cb16 <- read.csv("campeonatoBrasileiro2016.csv", sep = "," )

For this plot to work I need to turn this big table to a more long, less column format.

library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(tidyr)
names(cb16) <- gsub("X","",names(cb16))
cb16N <- cb16 %>% gather(Round, Position, -Times)

cb16N$Round <- as.factor(as.numeric(cb16N$Round))

Plotting

Now we can plot it!

For plot it I will force lines and reverse de Y axis, since position should be higher as close to 1 (first position).

library(plotly)

plot_ly(data=cb16N, x=~Round, y=~Position, color=~Times, type = 'scatter', mode = 'lines') %>%
  layout(yaxis = list(autorange = "reversed"), hovermode = 'x')

Second thoughts

It’s a lot of data. since there are 38 rounds and 20 teams. I will keep just the 5 top teams at the last round.

top <- cb16$Times[cb16[39] < 6]

cb16Top <- subset(cb16N, Times %in% top)

plot_ly(data=cb16Top, x=~Round, y=~Position, color=~Times, type = 'scatter', mode = 'lines') %>%
  layout(yaxis = list(autorange = "reversed"), hovermode = 'x')