forked from plotly/documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2016-11-29-axis-text.Rmd
142 lines (106 loc) · 3.64 KB
/
2016-11-29-axis-text.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
---
title: ggplot2 Axis Text | Examples | Plotly
name: Axis Text
permalink: ggplot2/axis-text/
description: How to modify axis titles in R and ggplot2.
layout: base
thumbnail: thumbnail/theme_image.png
language: ggplot2
page_type: example_index
has_thumbnail: true
display_as: layout_opt
output:
html_document:
keep_md: true
---
```{r, echo = FALSE, message=FALSE}
knitr::opts_chunk$set(message = FALSE, warning=FALSE)
Sys.setenv("plotly_username"="RPlotBot")
Sys.setenv("plotly_api_key"="q0lz6r5efr")
```
### New to Plotly?
Plotly's R library is free and open source!<br>
[Get started](https://plot.ly/r/getting-started/) by downloading the client and [reading the primer](https://plot.ly/r/getting-started/).<br>
You can set up Plotly to work in [online](https://plot.ly/r/getting-started/#hosting-graphs-in-your-online-plotly-account) or [offline](https://plot.ly/r/offline/) mode.<br>
We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/r_cheat_sheet.pdf) (new!) to help you get started!
### Version Check
Version 4 of Plotly's R package is now [available](https://plot.ly/r/getting-started/#installation)!<br>
Check out [this post](http://moderndata.plot.ly/upgrading-to-plotly-4-0-and-above/) for more information on breaking changes and new features available in this version.
```{r}
library(plotly)
packageVersion('plotly')
```
### Axis Text Size
```{r, results='hide'}
library(plotly)
set.seed(123)
df <- diamonds[sample(1:nrow(diamonds), size = 1000),]
p <- ggplot(df, aes(carat, price, color = color, alpha = cut)) +
geom_point() +
theme(axis.text.x = element_text(colour = "#ff6666", size = 20),
axis.text.y = element_text(colour = "#668cff", size = 20))
p <- ggplotly(p)
# Create a shareable link to your chart
# Set up API credentials: https://plot.ly/r/getting-started
chart_link = plotly_POST(p, filename="axis-text/size")
chart_link
```
``` {r, echo=FALSE}
chart_link
```
### Axis Text Blank
```{r, results='hide'}
library(plotly)
set.seed(123)
df <- diamonds[sample(1:nrow(diamonds), size = 1000),]
p <- ggplot(df, aes(carat, price, color = cut)) +
geom_point() +
theme(axis.text = element_blank())
p <- ggplotly(p)
# Create a shareable link to your chart
# Set up API credentials: https://plot.ly/r/getting-started
chart_link = plotly_POST(p, filename="axis-text/blank")
chart_link
```
``` {r, echo=FALSE}
chart_link
```
### Vertical Text
```{r, results='hide'}
library(plotly)
lab <- paste("Vertical Label", c(1, 2, 3, 4, 5))
ds <- data.frame(x = sample(lab, size = 1000, replace = T),
y = sample(LETTERS[1:5], size = 1000, replace = T))
p <- ggplot(ds, aes(x = x, fill = y)) +
geom_bar() +
theme(axis.text.x = element_text(angle = 90)) +
ggtitle("Vertical Axis Labels")
p <- ggplotly(p)
# Create a shareable link to your chart
# Set up API credentials: https://plot.ly/r/getting-started
chart_link = plotly_POST(p, filename="axis-text/vertical")
chart_link
```
``` {r, echo=FALSE}
chart_link
```
### Angled Text
```{r, results='hide'}
library(plotly)
lab <- paste("Angle Label", c(1, 2, 3, 4, 5))
ds <- data.frame(x = sample(lab, size = 1000, replace = T),
y = sample(LETTERS[1:5], size = 1000, replace = T))
p <- ggplot(ds, aes(x = x, fill = y)) +
geom_bar() +
theme(axis.text.x = element_text(angle = 45)) +
ggtitle("Angle Axis Labels")
p <- ggplotly(p)
# Create a shareable link to your chart
# Set up API credentials: https://plot.ly/r/getting-started
chart_link = plotly_POST(p, filename="axis-text/angled")
chart_link
```
``` {r, echo=FALSE}
chart_link
```
Inspired by <a href="http://docs.ggplot2.org/current/">ggplot2 documentation</a>