嗨,我已经将这个R脚本导入到PowerBI中,需要转换它,以便它从数据表中读取:
Update_Date(日期类型)/ Series(字符串类型)/ Milestone_Finish_Date(日期类型)
导入的数据示例如下
01/12/2023 A数据点名称13/12/2023
01/01/2024 A数据点名称20/12/2023
它是一个非常无聊的折线图,上面有一个三角形。
然而,它抛出一个摇摆不定,坦率地说,虽然我认为这是相当简单的,任何人都可以提供帮助,因为它做我的头。
# The following code to create a dataframe and remove duplicated rows is always executed and acts as a preamble for your script:
dataset <- data.frame(Milestone_Finish_Date, Series, Update_Date)
#dataset <- unique(dataset)
# Paste or type your script code here:
data = dataset
str(data)
library(ggplot2)
#setwd("C:/R-File")
#data <- read.csv("Data.csv")
# Convert string dates to actual date objects
data$Update_Date <- as.Date(data$Update_Date, format = "%d-%b-%y")
data$Milestone_Finish_Date <- as.Date(data$Milestone_Finish_Date, format = "%d-%b-%y")
# Create the milestone trend analysis chart with colored triangle area
ggplot(data, aes(x = Update_Date, y = Milestone_Finish_Date, group = Series)) +
geom_line(aes(color = Series), show.legend = TRUE, lwd = 1) + # Set show.legend to FALSE
geom_point(size = 1, show.legend = FALSE) + # Set show.legend to FALSE
geom_polygon(data = data.frame(
x = c(min(data$Update_Date), max(data$Update_Date), max(data$Update_Date), min(data$Update_Date)),
y = c(min(data$Milestone_Finish_Date), min(data$Milestone_Finish_Date), max(data$Milestone_Finish_Date), min(data$Milestone_Finish_Date)),
Series = rep("", 1)
), aes(x = x, y = y, fill = Series), alpha = 1, color = "grey", lwd = 1.1, show.legend = FALSE) + # Add a black border line
labs(title = "Milestone Trend Analysis Chart",
x = "Update Date",
y = "Milestone Finish Date") +
theme_minimal() +
theme(legend.position = "top") + # Remove legend title
guides(color = guide_legend(title = "Series")) + # Replace "Series" with your desired legend title
scale_fill_manual(values = "white") # Set the polygon fill color to white
字符串
1条答案
按热度按时间dz6r00yl1#
这个问题的答案为任何人奋斗。
不要修改R编辑器中“Paste or type your script code here:“上方的任何行:
要替换.csv读入,您只需将“data <- read.csv(“Data.csv”)”更改为data = dataset。工作完成。无需解析为str(data)或修改数据字段的格式,因为PowerBI中已经完成了。