%
mutate(
model = row.names(mtcars)
)
You can see I’m selecting 2 columns from mtcars in the first line, then adding a model column with mutate.
3) OK, ready to graph. This sets my data source:
tauchart(mtcars) %>%
Next line of code says I want a scatter plot, or graph with points, with weight on the x axis and mpg on my y axis:
tau_point("wt", "mpg") %>%
If you're familiar with ggplot2, note a difference here - you need the column names inside quotation marks with taucharts.
I want to add a tootip:
tau_tooltip() %>%
And I want to add trend line options
tau_trendline()
Run the code; then open results in a browser window, and voilà. Here’s an interactive scatterplot.
You can mouse over points to see underlying data. The tau_tooltip() command added all the columns in the graph's data set to the tooltip. That's why I wanted Models to be in a column.
tau_trendline() shows a linear regression line by default. But you can see there are several other options included.
That's how easy it is to create an interactive scatterplot with multiple trendline options in R!
As promised, here's information about installing taucharts. The package was written by security data scientist Bob Rudis. It's on his GitHub, at his hrbrmstr account. You can install it with the devtools package.
But another compelling option if you're lazy and don't want to have to type out the author’s GitHub account name is the githubinstall package. Install it with
install.packages("githubinstall")
and then run
githubinstall::githubinstall("taucharts")
It asks you if that's the one you want!
Type capital Y for yes and off you go.
That’s it for this episode, thanks for watching! For more R tips, follow me on Twitter at @sharon000. So long! ">
受欢迎的
来自IDG.tv的特色视频