SampleScatter: takes a sample for a scatter plot

View source: R/SampleScatter.R

SampleScatterR Documentation

takes a sample for a scatter plot

Description

Given 2D points having X and Y coordinates takes a sample, such that these points are is optimally visualized if a plot function is called.

Usage

SampleScatter(X, Y, ThresholdPoints = 20,

DensityThreshold, nbins = 100,na.rm=TRUE, PlotIt = FALSE)

Arguments

X

[1:n] x coordinate

Y

[1:n] y coordinate

ThresholdPoints

how many points per grid are allowed to overlap, default 20

DensityThreshold

default is internally estimated, scalar above zero and below 1, SDH threshold for density computed with SmoothedDensitiesXY, usually good values are around 0.1

nbins

number of bins in grid, default 100x100

na.rm

Function may not work with non finite values. If these cases should be automatically removed, set parameter TRUE

PlotIt

Plots the remaining points

Details

"Optimally"" visualized in the sense that not too much point overap visually. The lower the value for ThresholdPoints, the smaller is the sample that is taken by the function.

Value

SubsampleInd[1:m] indices of m points, m<n, that will be relevant for a optimal scatter plot

Author(s)

Michael Thrun

See Also

SmoothedDensitiesXY

Examples




if(requireNamespace("DataVisualizations")){
data("ITS",package = "DataVisualizations")
data("MTY",package = "DataVisualizations")
sample_ind=SampleScatter(ITS,MTY,PlotIt=TRUE)
}else{
#sample random data
ITS=rnorm(10000)
MTY=rnorm(10000)
sample_ind=SampleScatter(ITS,MTY,ThresholdPoints = 5)
del_ind=setdiff(1:length(ITS),sample_ind)
plot(ITS,MTY,type="p",pch=20,col="grey",main="Grey=full data, red=overlapping data points")
points(ITS[del_ind],MTY[del_ind],type="p",pch=20,col="red")
}




ScatterDensity documentation built on April 15, 2025, 5:09 p.m.