This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
library(ggplot2)
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(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
setwd("C:/Users/Edemd/OneDrive/Data Science 110/data")
top100tennis_clean<-read.csv("top100tennis_clean.csv")
library(plotly)
plot_ly(top100tennis_clean, x = top100tennis_clean$rank, y= top100tennis_clean$points, size = top100tennis_clean$tourn.played, text = paste("Country:", top100tennis_clean$country))
## No trace type specified:
## Based on info supplied, a 'scatter' trace seems appropriate.
## Read more about this trace type -> https://plot.ly/r/reference/#scatter
## No scatter mode specifed:
## Setting the mode to markers
## Read more about this attribute -> https://plot.ly/r/reference/#scatter-mode
## Warning: `line.width` does not currently support multiple values.
library(plotly)
top100tennis_clean$country <- as.factor(c( 'ROU', 'GER', 'DEN', 'JPN', 'USA', 'UKR', 'CZE', 'CZE', 'NED', 'RUS', 'BLR', 'BEL', 'LAT', 'GER', 'USA', 'USA', 'USA', 'ESP', 'FRA', 'EST', 'CHN', 'LAT', 'ESP', 'UKR', 'ROU', 'SVK', 'ITA', 'TPE', 'CRO', 'RUS', 'CRO', 'CZE', 'BLR', 'AUS', 'USA', 'CZE', 'USA', 'GBR', 'CHN', 'CHN', 'GRE', 'RUS', 'FRA', 'KAZ', 'AUS', 'SVK', 'FRA', 'USA', 'BEL', 'SVK', 'BEL', 'BLR', 'PUR', 'FRA', 'SUI', 'USA', 'RUS', 'TUN', 'UKR', 'SRB', 'GER', 'SWE', 'BLR', 'CHN', 'HUN', 'THA', 'CZE', 'RUS', 'USA', 'EST', 'GER', 'RUS', 'AUS', 'GER', 'SWE', 'ROU', 'SVK', 'SLO', 'CAN', 'ESP', 'ROU', 'SLO', 'ESP', 'ROU', 'SUI', 'POL', 'USA', 'ROU', 'USA', 'RUS', 'RUS', 'SLO', 'GBR', 'USA', 'RUS', 'RUS', 'UKR', 'KAZ', 'GBR', 'USA'))
p <- plot_ly(top100tennis_clean, x = ~rank, y = ~points, text = paste("Age:",top100tennis_clean$age, "Name:", top100tennis_clean$player), type = 'scatter', mode = 'markers', size = ~tourn.played, color = ~country, colors = 'Paired',
sizes = c(10, 50),
marker = list(opacity = 0.5, sizemode = 'diameter')) %>%
layout(title = 'Top 100 Women Tennis players in the World',
xaxis = list(showgrid = TRUE),
yaxis = list(showgrid = TRUE),
showlegend = FALSE,
xlab ="Rank",
ylab =" Points Earned")
p
## Warning: `line.width` does not currently support multiple values.
## Warning: `line.width` does not currently support multiple values.
## Warning: `line.width` does not currently support multiple values.
## Warning: `line.width` does not currently support multiple values.
## Warning: `line.width` does not currently support multiple values.
## Warning: `line.width` does not currently support multiple values.
## Warning: `line.width` does not currently support multiple values.
## Warning: `line.width` does not currently support multiple values.
## Warning: `line.width` does not currently support multiple values.
## Warning: `line.width` does not currently support multiple values.
## Warning: `line.width` does not currently support multiple values.
## Warning: `line.width` does not currently support multiple values.
## Warning: `line.width` does not currently support multiple values.
## Warning: `line.width` does not currently support multiple values.
## Warning: `line.width` does not currently support multiple values.
## Warning: `line.width` does not currently support multiple values.
## Warning: `line.width` does not currently support multiple values.
## Warning: `line.width` does not currently support multiple values.
## Warning: `line.width` does not currently support multiple values.
## Warning: `line.width` does not currently support multiple values.
## Warning: `line.width` does not currently support multiple values.
## Warning: 'layout' objects don't have these attributes: 'xlab', 'ylab'
## Valid attributes include:
## 'font', 'title', 'autosize', 'width', 'height', 'margin', 'paper_bgcolor', 'plot_bgcolor', 'separators', 'hidesources', 'showlegend', 'colorway', 'colorscale', 'datarevision', 'uirevision', 'editrevision', 'selectionrevision', 'template', 'modebar', 'meta', 'transition', '_deprecated', 'clickmode', 'dragmode', 'hovermode', 'hoverdistance', 'spikedistance', 'hoverlabel', 'selectdirection', 'grid', 'calendar', 'xaxis', 'yaxis', 'ternary', 'scene', 'geo', 'mapbox', 'polar', 'radialaxis', 'angularaxis', 'direction', 'orientation', 'editType', 'legend', 'annotations', 'shapes', 'images', 'updatemenus', 'sliders', 'metasrc', 'barmode', 'bargap', 'mapType'
Note that the echo = FALSE
parameter was added to the code chunk to prevent printing of the R code that generated the plot.