データセットをステップ実行して、因子ごとにヒストグラムと要約テーブルを作成し、出力を .xml ファイルとして保存しようとしています.svg
。ヒストグラムは を使用ggplot2
して作成され、サマリー テーブルは を使用して作成されますsummary()
。
.pdf
以下のコードを使用して、関連するヒストグラム/テーブルを含む各ページで出力を単一に保存することに成功しました。ただし、ヒストグラムのみを使用して各ヒストグラム/テーブル コンボを一連の.svg
画像に保存しようとすると、. 表はただの空白です。ggsave
ggplot
.svg
dev.copy
Cairo
andを使用してみましsvg
たが、すべて同じ結果になります。ヒストグラムはレンダリングされますが、テーブルはレンダリングされません。画像をテーブルとして保存すると.png
、テーブルが表示されます。
iris
データを再現可能なデータセットとして使用しています。私がR-Studio
見たものは使用していませんが、他の人に「空のプロット」の悲しみを引き起こしていました。
#packages used
library(ggplot2)
library(gridExtra)
library(gtable)
library(Cairo)
#Create iris histogram plot
iris.hp<-ggplot(data=iris, aes(x=Sepal.Length)) +
geom_histogram(binwidth =.25,origin=-0.125,
right = TRUE,col="white", fill="steelblue4",alpha=1) +
labs(title = "Iris Sepal Length")+
labs(x="Sepal Length", y="Count")
iris.list<-by(data = iris, INDICES = iris$Species, simplify = TRUE,FUN = function(x)
{iris.hp %+% x + ggtitle(unique(x$Species))})
#Generate list of data to create summary statistics table
sum.str<-aggregate(Sepal.Length~Species,iris,summary)
spec<-sum.str[,1]
spec.stats<-sum.str[,2]
sum.data<-data.frame(spec,spec.stats)
sum.table<-tableGrob(sum.data)
colnames(sum.data) <-c("species","sep.len.min","sep.len.1stQ","sep.len.med",
"sep.len.mean","sep. len.3rdQ","sep.len.max")
table.list<-by(data = sum.data, INDICES = sum.data$"species", simplify = TRUE,
FUN = function(x) {tableGrob(x)})
#Combined histogram and summary table across multiple plots
multi.plots<-marrangeGrob(grobs=(c(rbind(iris.list,table.list))),
nrow=2, ncol=1, top = quote(paste(iris$labels$Species,'\nPage', g, 'of',pages)))
#bypass the class check per @baptiste
ggsave <- ggplot2::ggsave; body(ggsave) <- body(ggplot2::ggsave)[-2]
#
for(i in 1:3){
multi.plots<-marrangeGrob(grobs=(c(rbind(iris.list[i],table.list[i]))),
nrow=2, ncol=1,heights=c(1.65,.35),
top = quote(paste(iris$labels$Species,'\nPage', g, 'of',pages)))
prefix<-unique(iris$Species)
prefix<-prefix[i]
filename<-paste(prefix,".svg",sep="")
ggsave(filename,multi.plots)
#dev.off()
}
@rawr が参照したテーマ tt3 を編集して削除しました。サンプルコードに誤って残されていました。誰かが興味を持った場合に備えて、それは問題の原因ではありませんでした.