但是以某种方式,我无法使用stat_function
使它正常工作。我收到argument missing
错误。添加args=list(..)
不起作用。
limitRange <- function(fun, min, max) {
function(x) {
y <- fun(x)
y[x < min | x > max] <- NA
return(y)
}
}
ggplot(data.frame(x=c(0,3)), aes(x)) +
stat_function(fun = dweibull,
args = list(shape = 2, scale = 1.12), alpha = .8, size = 1.1) + # works
stat_function(fun = limitRange(dweibull(shape = 2, scale = 1.12), 0.0297, 0.1189),
args = list(shape = 2, scale = 1.12), #doesn't work
geom = "area", fill = "blue", alpha = 0.2)
非常感谢任何帮助。
答案 0 :(得分:3)
您的问题是您致电dataLoaded = false;
ngOnInit() {
this.getListings()
}
getListings() {
this.serviceHomeScreen.getAllListingsDetails().subscribe((data) => {
this.extractlistings(data[0]);
})
}
extractlistings(data) {
this.locations = data;
this.dataLoaded = true;
console.log(this.locations[1]); // has the right value
}
mapReady(map) {
console.log(this.locations[1]); // now defined
for (let i = 0; i < this.locations.length; i++) {
console.log("aici")
return new google.maps.Marker({
position: { lat: this.locations[i].lat, lng: this.locations[i].long },
map: map,
});
}
}
的方式。它的第一个参数必须是一个函数,但是您给它<agm-map
*ngIf="dataLoaded"
id="map_"
[zoom]="30"
[fitBounds]="true"
[latitude]="lat"
[longitude]="lng"
[streetViewControl]="false"
[zoomControl]="false"
(mapReady)="mapReady($event)">
</agm-map>
而不是一个函数。实际上,是导致错误的原因:
limitRange
将其转换为功能有效:
dweibull(shape = 2, scale = 1.12)
更简洁的方法是为dweibull(shape = 2, scale = 1.12)
# Error in dweibull(shape = 2, scale = 1.12) :
# argument "x" is missing, with no default
赋予ggplot(data.frame(x = c(0, 2)), aes(x)) +
stat_function(fun = dweibull,
args = list(shape = 2, scale = 1.12)) +
stat_function(
fun = limitRange(function(z) dweibull(z, shape = 2, scale = 1.12), 0.0297, 0.1189),
geom = "area",
fill = "blue",
alpha = 0.2
)
一个limitRange
参数:
...
您将需要以这种方式命名fun
和limitRange <- function(fun, ..., min, max) {
return(function(x) {
y <- fun(x, ...)
y[x < min | x > max] <- NA
return(y)
})
}
ggplot(data.frame(x = c(0, 2)), aes(x)) +
stat_function(fun = dweibull,
args = list(shape = 2, scale = 1.12)) +
stat_function(
fun = limitRange(dweibull, shape = 2, scale = 1.12, min = 0.0297, max = 0.1189)
geom = "area",
fill = "blue",
alpha = 0.2
)
参数(如果min
接受max
和fun
参数,可能会导致错误。 。越多的唯一名称可能会越好)。