R скрипт не запускает гистограмму из bash - PullRequest
0 голосов
/ 11 ноября 2018

У меня есть гистограмма.R с chmod 755. Я хочу отобразить гистограмму. С консоли R (с удалением "#! / Usr / bin / env Rscript") это работает, но не когда я запускаю скрипт из своей оболочки. Просто делая: ./histogram.R У меня есть это для вывода:

 [1] 58384 67239 23702 32667 60158 21209 49167 33010 20278 46316 35619    NA
[13] 26647    NA 44791 21630 41907 58796 15578 56909 46550

Это мой код:

#!/usr/bin/env Rscript
contenuTotalFichier <- read.csv("./resources/dataset_train.20.csv")
colonne.Arithmancy <- contenuTotalFichier["Arithmancy"][,1]
print(colonne.Arithmancy)

hist(colonne.Arithmancy, col = grey(0.9), border = grey(0.2),
main = paste("Quel cours de Poudlard a une répartition des notes homogènes entre les quatres maisons
?"),
xlab = "effectifs en fonction des maisons",
ylab = "cours de Poudlard",
labels = TRUE, las = 1, ylim = c(0, 50))

Найти решение: сохранить график в формате pdf и открыть его после ggplot2 (пример с общими данными)

library(ggplot2)
data=data.frame(x=rnorm(100))
plot=qplot(x, data=data, geom="histogram") 
ggsave(plot,file="graph1.pdf")
system("open graph1.pdf")

1 Ответ

0 голосов
/ 11 ноября 2018
#!/usr/bin/env Rscript
contenuTotalFichier <- read.csv("./resources/dataset_train.20.csv")
colonne.Arithmancy <- contenuTotalFichier["Arithmancy"][,1]
print(colonne.Arithmancy)

x11() # if you're on linux; quartz() if macOS

hist(colonne.Arithmancy, col = grey(0.9), border = grey(0.2),
main = paste("Quel cours de Poudlard a une répartition des notes homogènes entre les quatres maisons
?"),
xlab = "effectifs en fonction des maisons",
ylab = "cours de Poudlard",
labels = TRUE, las = 1, ylim = c(0, 50))

invisible(readLines("stdin", n=1)) # Wait for ENTER so the chart stays up
dev.off() # close the X11 device

Сделайте то, что предложил Майкл, если вы хотите создать файл.

...