在 R 中將數據視覺化
R 生態系統提供多個圖形連結庫,其中包含許多不同的功能。 根據預設,Microsoft Fabric 中的每個 Apache Spark 集區都包含一組精心策劃且熱門的開放原始碼連結庫。 使用 Microsoft Fabric 連結庫管理功能新增或管理額外的連結庫或版本。
必要條件
取得 Microsoft Fabric 訂用 帳戶。 或者,註冊免費的 Microsoft Fabric 試用版。
登入 Microsoft Fabric。
使用首頁左側的體驗切換器,切換至 Synapse 資料科學 體驗。
開啟或建立筆記本。 若要瞭解如何,請參閱 如何使用 Microsoft Fabric 筆記本。
將語言選項設定為 SparkR (R) 以變更主要語言。
將筆記本附加至 Lakehouse。 在左側,選取 [新增 ] 以新增現有的 Lakehouse 或建立 Lakehouse。
ggplot2
ggplot2 連結庫很適合用於數據視覺效果和探勘數據分析。
%%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 是用來建立互動式圖形的原生 R 繪圖連結庫。
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
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 是 Highcharts JavaScript 連結庫及其模組的 R 包裝函式。
library(magrittr)
library(highcharter)
hchart(mtcars, "scatter", hcaes(wt, mpg, z = drat, color = hp)) %>%
hc_title(text = "Scatter chart with size and color")