-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy path2021-08-04-plot-data-from-csv.Rmd
41 lines (32 loc) · 1.12 KB
/
2021-08-04-plot-data-from-csv.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
---
description: How to Plot CSV Data in ggplot2 with Plotly.
name: Plot CSV Data
permalink: ggplot2/plot-data-from-csv/
thumnail_github: csv.png
layout: base
language: ggplot2
display_as: advanced_opt
page_type: u-guide
order: 1
output:
html_document:
keep_md: true
---
```{r, echo = FALSE, message=FALSE}
knitr::opts_chunk$set(message = FALSE, warning=FALSE)
```
## Plot from CSV
When reading in files most often `stringsAsFactors = FALSE` is used. This setting ensures that non-numeric data (strings) are not converted to factors.
A factor is similar to a category. However factors can be numerically interpreted (they can have an order) and may have a level associated with them.
```{r}
library(plotly)
require(ggplot2)
df <- read.csv("https://raw.githubusercontent.com/plotly/datasets/master/iris-data.csv",
stringsAsFactors = FALSE)
p <- ggplot(data=iris, aes(x = Sepal.Length, y = Sepal.Width))
p <- p + geom_point(aes(color=Species, shape=Species)) +
xlab("Sepal Length") + ylab("Sepal Width") +
ggtitle("Sepal Length-Width")
ggplotly(p)
```
<!--------------------- EXAMPLE BREAK ------------------------->