1

我可以做一个 sparkBar,但没有 sparkHist。这可能吗?

这是如何创建 sparkBar 的示例(来自example(newSparkBar)

library(sparkTable)
data(pop)
x <- pop[pop[,2]=="Insgesamt",3]
b <- newSparkBar(values=x-min(x))
getParameter(b, type="values")
b <- setParameter(b, c("darkred", "darkgreen","black"), type="barCol")
plotSparks(b, outputType="pdf", filename="testBar1")
4

2 回答 2

2

阅读此处的评论后,我在 sparkTable 包的 0.9.4 版本中包含了直方图。基本上与上一个答案建议的风格相同。

这里有两个例子:

1)仅用于绘制 sparkHist(不是很令人兴奋)

2) 用于为正态和对数正态分布数据创建带有箱线图和直方图的 sparkTable

#Example newSparkHist
hh <- newSparkHist(values=rnorm(100))
plotSparks(hh, outputType='pdf', filename='testHist1')


#Example sparkTable with Hist+Box with 2 variables in 10 different groups
datEx <- data.frame(variable=sample(paste("Cat",1:10,sep="_"),1000,replace=TRUE),
  value=rnorm(1000),value2=rlnorm(1000))
b <- newSparkBox()
h <- newSparkHist()
content <- list(function(x) { round(mean(x),2) },
  function(x) { round(median(x),2) },
  function(x) { round(quantile(x,.25),2) },
  function(x) { round(quantile(x,.75),2) },
  b,
  h,
  function(x) { round(mean(x),2) },
  function(x) { round(median(x),2) },
  function(x) { round(quantile(x,.25),2) },
  function(x) { round(quantile(x,.75),2) },
  b,
  h
  )
names(content) <- c(paste(c("Mean","Median","Q25","Q75","Boxplot","Histogram"),
  "_v1",sep=""),
  paste(c("Mean","Median","Q25","Q75","Boxplot","Histogram"),"_v2",sep="")
)
varType <- c(rep("value",length(content)/2),rep("value2",length(content)/2))
datEx <- reshapeExt(datEx,idvar="variable", varying=list(2,3))
x2 <- newSparkTable(datEx, content, varType)
plotSparkTable(x2, outputType="html", graphNames="o2",filename="t1")
于 2012-06-06T06:28:04.733 回答
0

这样的事情是你的想法吗?(它可以很容易地被包装成一个newSparkHist函数,但我没有打扰......)

library(sparkTable)
data(alcohol)
hvals <- hist(alcohol$value,plot=FALSE)$counts
b <- newSparkBar(values=hvals,barCol=c("gray","gray","black"))
plotSparks(b, outputType="png", filename="testBar1")

在此处输入图像描述

于 2012-05-24T23:15:20.527 回答