Show Sidebar Hide Sidebar

# Carpet Scatter Plot in R

How to create carpet plots in R with Plotly.

### New to Plotly?

Plotly's R library is free and open source!
You can set up Plotly to work in online or offline mode.
We also have a quick-reference cheatsheet (new!) to help you get started!

### Version Check

Version 4 of Plotly's R package is now available!
Check out this post for more information on breaking changes and new features available in this version.

``````library(plotly)
packageVersion('plotly')
``````
``````## [1] '4.7.0'
``````

### Basic Carpet Plot

``````library(plotly)

p <- plot_ly(
type = 'carpet',
a = c(4, 4, 4, 4.5, 4.5, 4.5, 5, 5, 5, 6, 6, 6),
b = c(1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3),
y = c(2, 3.5, 4, 3, 4.5, 5, 5.5, 6.5, 7.5, 8, 8.5, 10),
aaxis = list(
tickprefix = 'a = ',
ticksuffix = 'm',
smoothing = 1,
minorgridcount = 9
),
baxis = list(
tickprefix = 'b = ',
ticksuffix = 'Pa',
smoothing = 1,
minorgridcount = 9
)
)

# Set up API credentials: https://plot.ly/r/getting-started
chart_link = api_create(p, filename="scattercarpet-basic", sharing = 'public')
``````

``````library(plotly)

p <- plot_ly(
type = 'carpet',
a = c(4, 4, 4, 4.5, 4.5, 4.5, 5, 5, 5, 6, 6, 6),
b = c(1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3),
y = c(2, 3.5, 4, 3, 4.5, 5, 5.5, 6.5, 7.5, 8, 8.5, 10),
aaxis = list(
tickprefix = 'a = ',
ticksuffix = 'm',
smoothing = 1,
minorgridcount = 9
),
baxis = list(
tickprefix = 'b = ',
ticksuffix = 'Pa',
smoothing = 1,
minorgridcount = 9
)
) %>%
type = 'scattercarpet',
a = c(4, 4.5, 5, 6),
b = c(2.5, 2.5, 2.5, 2.5),
line = list(
shape = 'spline',
smoothing = 1,
color = 'blue'
),
marker = list(color = "blue")
)

# Set up API credentials: https://plot.ly/r/getting-started
``````
``````## Error: Client error: (400) Bad Request
##  Figure field is invalid. Reason: Raw data arrays are not allowed at this endpoint. Use grid references instead. Raw data found at the following paths in the figure [('data', 1, u'y')]
``````
``````chart_link
``````

``````library(plotly)

p <- plot_ly() %>%
type = 'carpet',
a = c(4, 4, 4, 4.5, 4.5, 4.5, 5, 5, 5, 6, 6, 6),
b = c(1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3),
y = c(2, 3.5, 4, 3, 4.5, 5, 5.5, 6.5, 7.5, 8, 8.5, 10),
aaxis = list(
tickprefix = 'a = ',
ticksuffix = 'm',
smoothing = 1,
minorgridcount = 9
),
baxis = list(
tickprefix = 'b = ',
ticksuffix = 'Pa',
smoothing = 1,
minorgridcount = 9
)
) %>%
type = 'scattercarpet',
a = c(4, 4.5, 5, 6),
b = c(2.5, 2.5, 2.5, 2.5),
mode = 'markers+lines',
line = list(
shape = 'spline',
smoothing = 1,
color = "blue"
),
marker = list(color = "blue")
) %>%
type = 'scattercarpet',
a = c(4, 4.5, 5, 6),
b = c(1.5, 1.5, 1.5, 1.5),
mode = 'lines',
line = list(
shape = 'spline',
smoothing = 1,
color = "green"
)
) %>%
type = 'scattercarpet',
a = c(5, 5, 5, 5),
b = c(1, 1.5, 2, 3),
mode = 'markers',
marker = list(
color = "red",
size = c(0,0,20,0)
)
) %>%
type = 'scattercarpet',
a = c(4.5, 4.5, 4.5, 4.5),
b = c(1, 1.5, 2, 3),
mode = 'markers',
marker = list(
color = "black",
size = c(0,0,30,0)
)
)