21 February 2020

Info of the Plot

The plot shows the correlation of two of the main car variables that correlate pretty well with fuel consumption.

The data is from the R dataset “mtcars” (a dataset of 32 automobiles from 1973-74).

The plot features an interactive label that allows the easy identification of the car.

The two variables or dependant variables are:

  • wt Weight (1000 lbs)
  • hp Gross horsepower

and the independent variable is:

  • mpg Miles/(US) gallon

Code of the Plot

 library(plotly)

cars<-mtcars
cars$car<-rownames(mtcars)

p <- plot_ly(cars) %>%
  add_trace(type = 'scatter',
            mode = 'markers',
            x = ~wt, y = ~mpg,
            color = ~hp, size = ~hp, 
            # Hover text: 
            text = ~paste('<b>',car, '</b><br>',
                        'Power: ',hp,' hp<br>'), 
            hoverinfo = 'text')

Slide With Plot

Thanks for watching