生活随笔
收集整理的這篇文章主要介紹了
如何使用R语言在SAP Analytics Cloud里绘制各种统计图表
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
插入一個R visualization:
一定要確保圖形出現(xiàn)這個model的小圖標(biāo),代表這個R visualization的模型數(shù)據(jù)成功綁定之后才能進行下一步操作:
模型綁定成功后,在R script編輯器Environment標(biāo)簽頁的Data下拉菜單里能看到模型數(shù)據(jù)。
使用這個SAP Analytics Cloud官方教程里提供的excel文件作為數(shù)據(jù)源:
https://www.sapanalytics.cloud/tutorial-r-visualization/
該excel內(nèi)容如下:
excel系統(tǒng)導(dǎo)入SAP Analytics Cloud后,需要使用simple transformation,將;分號分隔的值拆分成三列:
逐一拆分:
拆分完畢之后,生成Model. 將這個url里包含的R腳本復(fù)制粘貼到R編輯器里:
https://www.sapanalytics.cloud/wp-content/uploads/2019/09/R-Script-Plot.txt
# Discription:
# Creating a histogram of the log returns, adding the kernel density of the log returns
# and the normal density as reference distribution
#
# Requirements:
# ggplot requires a data frame
#
# Output:
# Histogram Plot
# library(ggplot2)Simulated_data <- data.frame(Simulated_data)histgg <- ggplot(data = Simulated_data, aes(logreturns))histgg + geom_histogram(aes(y = ..density..),fill = "lightblue",color = "black", alpha = 0.8, position = "identity") +geom_density(aes(color = "Kernel Density"), size = 1) +stat_function(aes(color = "Normal Distribution"), fun = dnorm, args = list(mean = mean(Simulated_data$logreturns), sd = sd(Simulated_data$logreturns)), size = 1) +ggtitle("Histogram") +theme(panel.grid = element_line(linetype = "dashed", color = "lightgrey"), panel.background = element_rect(fill = "white"),panel.border = element_rect(colour = "black", fill=NA),plot.title = element_text(hjust = 0.5)) +scale_colour_manual("Density", values = c("red", "darkgreen")) +xlab(" ")+ylab("Frequency")
點擊Execute按鈕,就可以看到R腳本繪制出來的圖形了:
要獲取更多Jerry的原創(chuàng)文章,請關(guān)注公眾號"汪子熙":
總結(jié)
以上是生活随笔為你收集整理的如何使用R语言在SAP Analytics Cloud里绘制各种统计图表的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。