我尝试使用数据中的列设置标记大小,但是值为1,2,5等的标记的大小会根据基础数据而变化。是否可以设置具有精确像素大小的标记大小?这样,当我的数据更改相同大小的标记时,无论基础数据如何,都将始终具有相同的关联值。
这是一个简单的例子:
第一个显示所有标记都很大(绝对不是1px,正如您可能从变量(function () {
'use strict';
angular
.module(usbeefConstants.generateName(usbeefConstants.appModule, usbeefConstants.NAMETYPES.module))
.directive(usbeefConstants.generateName('pivot', usbeefConstants.NAMETYPES.directive), pivot);
pivot.$inject = ['logger'];
function pivot(logger) {
// Usage:
// <test-metrodb-pivot></test-metrodb-pivot>
// Creates:
// testMetrodbPivot in javascript
//
var directive = {
restrict: 'E',
scope: {
},
link: function (scope, element, attrs, controller) {
// this doesn't work
// how do i fix this?
var elem = element[0];
var car_m_2 = elem('#section').data('carousel');
var thumbs = elem('#section-indexes > .pivot');
elem.each(thumbs, function () {
var thumb = elem(this);
index = thumb.data('index') - 1;
thumb.on('click', function () {
car_m_2.slideTo(index);
});
});
//
/* this works as is */
//$(function () {
// var car_m_2 = $('#section').data('carousel');
// var thumbs = $('#section-indexes > .pivot');
// $.each(thumbs, function () {
// var thumb = $(this), index = thumb.data('index') - 1;
// thumb.on('click', function () {
// car_m_2.slideTo(index);
// });
// });
//});
},
controller: pivotController,
controllerAs: 'pivot',
templateUrl: '/App/directives/pivot.directive.html'
};
return directive;
}
pivotController.$inject = ['$scope', 'logger'];
function pivotController($scope, logger) {
var pivot = this;
pivot.pivot = [];
activate();
function activate() {
logger.log('pivot.directive.js - activate() completed');
}
}
})();
解释的那样。
n
第二个调整了大小,但仅限于一组。两组的大小为1略有不同。
library(plotly)
dat <- data.frame(y=factor(c(1,1,2,2),levels=c(1,2),labels=c("GRP1","GRP2")),
x=c(1,2,3,4),
n=c(1,1,1,1),
grp=c("GRP1","GRP1","GRP2","GRP2"))
plot_ly(dat) %>%
add_markers(x = ~x,
y = ~y, color = ~grp,
size = ~n,
opacity = .7) %>%
layout(showlegend=F)
我尝试使用选项dat2 <- data.frame(y=factor(c(1,1,2,2),levels=c(1,2),labels=c("GRP1","GRP2")),
x=c(1,2,3,4),
n=c(1,2,1,1),
grp=c("GRP1","GRP1","GRP2","GRP2"))
plot_ly(dat2) %>%
add_markers(x = ~x,
y = ~y, color = ~grp,
size = ~n,
opacity = .7) %>%
layout(showlegend=F)
和sizes
,但这些似乎只能解决部分问题。
marker=list(sizeref=0.1,sizemode="area")
我正在寻找一种简单的方法来提供每个标记的大小,方法是明确地给它提供像素大小。我还尝试删除plot_ly(dat2) %>%
add_markers(x = ~x,
y = ~y, color = ~grp,
size = ~n,
sizes = c(10,50),
opacity = .7) %>%
layout(showlegend=F)
plot_ly(dat2) %>%
add_markers(x = ~x,
y = ~y, color = ~grp,
size = ~n,
marker=list(sizeref=0.1, sizemode="area"),
opacity = .7) %>%
layout(showlegend=F)
中的~
,但这只是给了我一个错误。我错过了什么......这可能吗?
感谢。
编辑:
此示例清楚地显示了该问题,请注意我将大小乘以400,size = ~n
定义如上:
dat2
两个蓝点(尺寸为400 * 1)与第一个绿点(尺寸为400 * 1)的尺寸不同。
plot_ly(dat2) %>%
add_markers(x = ~x,
y = ~y, color = ~grp,
size = ~I(400*n),
text = ~paste0("Size of marker: ",n),
opacity = .7,
type="scatter") %>%
layout(showlegend=F)
答案 0 :(得分:1)
根据github上的cpsievert的回答是在size
参数中使用marker
的较低级别控件:
plot_ly(x = 1:4, y = 1:4, size = 1:4, marker = list(size = 4:1 * 10, sizemode = "diameter"))
使用他的例子我的代码现在变为:
library(plotly)
dat <- data.frame(y=factor(c(1,1,2,2),levels=c(1,2),labels=c("GRP1","GRP2")),
x=c(1,2,3,4),
n=c(1,1,1,1),
grp=c("GRP1","GRP1","GRP2","GRP2"))
plot_ly(dat) %>%
add_markers(x = ~x,
y = ~y, color = ~grp,
marker = list(size=~I(n*10)),
opacity = .7) %>%
layout(showlegend=F)
dat2 <- data.frame(y=factor(c(1,1,2,2),levels=c(1,2),labels=c("GRP1","GRP2")),
x=c(1,2,3,4),
n=c(1,2,1,1),
grp=c("GRP1","GRP1","GRP2","GRP2"))
plot_ly(dat2) %>%
add_markers(x = ~x,
y = ~y, color = ~grp,
marker = list(size=~I(n*10)),
opacity = .7) %>%
layout(showlegend=F)