使用rCharts和dimple.js无法正确绘制散点图/气泡图

时间:2014-04-17 14:19:07

标签: r rcharts dimple.js

我正在尝试使用dimple和rCharts创建最简单的散点图。我很好奇是否有一些我对'scatter'类型的误解。当我运行此代码时,y轴值偏离10或更大的因子 - 几乎就像散点图作为堆积条形图而不是简单的散点图一样。下面的示例数据完全模仿了我的数据。

testdat1 <- data.frame(Recommend = sample(60:90, 200, replace = T), Quiet = sample(20:60, 200, replace = T),
                       Owner = as.factor(rep(c(1,2), 100)))
summary(testdat1) # no values exceed 90
dtest <- dPlot(Recommend ~ Quiet, groups = 'Owner', data = testdat1, type = 'scatter')
dtest # plotted y-values reach upwards of 450

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

请参阅注释,但可以通过以下代码块完成答案:

require(rCharts)

testdat1 <- data.frame(Recommend = sample(60:90, 200, replace = T), Quiet = sample(20:60, 200, replace = T),
                       Owner = as.factor(rep(c(1,2), 100)))
summary(testdat1) # no values exceed 90
dtest <- dPlot(Recommend ~ Quiet, groups = 'Owner', data = testdat1, type = 'bubble')
#will aggregate as avg by default
dtest$xAxis(type="addMeasureAxis")
dtest

#add x,y, and grouping so now only will aggregate where x,y,and group is exact same
#if still a problem, could a unique id and group on that
dtest$params$groups <- c('Recommend','Quiet','Owner')
dtest # plotted y-values reach upwards of 450