Skip to content

Latest commit

 

History

History
98 lines (69 loc) · 2.98 KB

File metadata and controls

98 lines (69 loc) · 2.98 KB
title Visualize data in R
description How to create R visualizations.
ms.author lagayhar
ms.reviewer ruxu
ms.topic how-to
ms.date 06/30/2025
ms.search.form R Language

Visualize data in R

The R ecosystem offers multiple graphing libraries that come packed with many different features. By default, every Apache Spark Pool in [!INCLUDE product-name] contains a set of curated and popular open-source libraries. Add or manage extra libraries or versions by using the [!INCLUDE product-name] library management capabilities.

Prerequisites

[!INCLUDE prerequisites]

[!INCLUDE r-prerequisites]

ggplot2

The ggplot2 library is popular for data visualization and exploratory data analysis.

:::image type="content" border="true" source="./media/r-visualization/ggplot2.png" alt-text="Screenshot of ggplot2 scatterplot.":::

%%sparkr
library(ggplot2)
data(mpg, package="ggplot2") 
theme_set(theme_bw()) 

g <- ggplot(mpg, aes(cty, hwy))

# Scatterplot
g + geom_point() + 
  geom_smooth(method="lm", se=F) +
  labs(subtitle="mpg: city vs highway mileage", 
       y="hwy", 
       x="cty", 
       title="Scatterplot with overlapping points", 
       caption="Source: midwest")

rbokeh

rbokeh is a native R plotting library for creating interactive graphics.

:::image type="content" border="true" source="./media/r-visualization/bokeh-plot.png" alt-text="Screenshot of rbokeh points.":::

library(rbokeh)
p <- figure() %>%
  ly_points(Sepal.Length, Sepal.Width, data = iris,
    color = Species, glyph = Species,
    hover = list(Sepal.Length, Sepal.Width))
p

R Plotly

Plotly is an R graphing library that makes interactive, publication-quality graphs.

:::image type="content" border="true" source="./media/r-visualization/rplot.png" alt-text="Screenshot of plot line.":::

library(plotly) 

fig <- plot_ly() %>% 
  add_lines(x = c("a","b","c"), y = c(1,3,2))%>% 
  layout(title="sample figure", xaxis = list(title = 'x'), yaxis = list(title = 'y'), plot_bgcolor = "#c7daec") 

fig

Highcharter

Highcharter is an R wrapper for Highcharts JavaScript library and its modules.

:::image type="content" border="true" source="./media/r-visualization/highchart.png" alt-text="Screenshot of highchart scatter.":::

library(magrittr)
library(highcharter)
hchart(mtcars, "scatter", hcaes(wt, mpg, z = drat, color = hp)) %>%
  hc_title(text = "Scatter chart with size and color")

Related content