I´m new to R and have problems to generate a for loop: I have a multidimensional array (NumPy File) in R and would like to automate the request of the part of the array. My array has a shape of (500, 192). I would like to plot a graph for Sample 1, 2 ... until sample 500.
AP has the structure: num [1:500, 1:192] 0.0323 0.0532 0.0135 0.0474 0.2026 ...
AP.shap has the structure: num [1:192] 3.23e-02 4.88e-04 1.39e-03 7.49e-04 5.82e-05 ...
library(reticulate)
library(RcppCNPy)
library(ggplot2)
#Sample 1
AP.shap <- (AP[1 ,]) # Sample 1
# convert to dataframe
typeof(AP.shap) # type double
AP.shap <- as.data.frame(AP.shap)
typeof(AP.shap) # list
# New Column with Nrow
AP.shap$Hour <- seq.int(nrow(AP.shap))
columnnames <- c("Shap", "Hour")
colnames(AP.shap) <- columnnames
#Plot
ggplot(AP.shap, aes(Hour, Shap))+
geom_bar(stat = "identity") + theme_minimal() +
ggtitle(expression(paste("Hours of Sample 1 - Air Pressure - G_PM"[1], " - All Season"))) +
xlab("Hour") +
ylab("Shap Value") +
ggsave("1_Hour_AP_G_allseason.png", plot = last_plot(), device = "png", path = "xy")
The next one would be:
#Sample 2
AP.shap <- (AP[**2** ,]) # Sample 1
# convert to dataframe
typeof(AP.shap) # type double
AP.shap <- as.data.frame(AP.shap)
typeof(AP.shap) # list
# New Column with Nrow
AP.shap$Hour <- seq.int(nrow(AP.shap))
columnnames <- c("Shap", "Hour")
colnames(AP.shap) <- columnnames
#Plot
ggplot(AP.shap, aes(Hour, Shap))+
geom_bar(stat = "identity") + theme_minimal() +
ggtitle(expression(paste("Hours of Sample **2** - Air Pressure - G_PM"[1], " - All Season"))) +
xlab("Hour") +
ylab("Shap Value") +
ggsave("**2**_Hour_AP_G_allseason.png", plot = last_plot(), device = "png", path = "xy")