Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jitter reproducibility in geom_jitter() #920

Merged
merged 7 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
Changing parameter name to align with the name in ggplot2.
  • Loading branch information
RYangazov committed Nov 8, 2023
commit b610d2e847d9edaf9f1247b3224a4924f3fa712a
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ class JitterDodgePos(
width: Double?,
jitterWidth: Double?,
jitterHeight: Double?,
jitterSeed: Long? = null
seed: Long? = null
) :
PositionAdjustment {
private val myJitterPosHelper: PositionAdjustment
private val myDodgePosHelper: PositionAdjustment

init {
myJitterPosHelper = JitterPos(jitterWidth, jitterHeight, jitterSeed)
myJitterPosHelper = JitterPos(jitterWidth, jitterHeight, seed)
myDodgePosHelper = DodgePos(aesthetics, groupCount, width)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ object PositionAdjustments {
width: Double?,
jitterWidth: Double?,
jitterHeight: Double?,
jitterSeed: Long?
seed: Long?
): PositionAdjustment {
return JitterDodgePos(aesthetics, groupCount, width, jitterWidth, jitterHeight, jitterSeed)
return JitterDodgePos(aesthetics, groupCount, width, jitterWidth, jitterHeight, seed)
}

enum class Meta(private val handlesGroups: Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ abstract class PosProvider {
}
*/

fun jitterDodge(width: Double?, jitterWidth: Double?, jitterHeight: Double?, jitterSeed: Long?): PosProvider {
fun jitterDodge(width: Double?, jitterWidth: Double?, jitterHeight: Double?, seed: Long?): PosProvider {
return object : PosProvider() {
override fun createPos(ctx: PosProviderContext): PositionAdjustment {
val aesthetics = ctx.aesthetics
Expand All @@ -126,7 +126,7 @@ abstract class PosProvider {
width,
jitterWidth,
jitterHeight,
jitterSeed
seed
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ object Option {
const val DODGE_WIDTH = "dodge_width"
const val JITTER_WIDTH = "jitter_width"
const val JITTER_HEIGHT = "jitter_height"
const val JITTER_SEED = "jitter_seed"
const val SEED = "seed"
}

object Stack {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ internal object PosProto {
opts.getDouble(Pos.JitterDodge.DODGE_WIDTH),
opts.getDouble(Pos.JitterDodge.JITTER_WIDTH),
opts.getDouble(Pos.JitterDodge.JITTER_HEIGHT),
opts.getLong(Pos.JitterDodge.JITTER_SEED)
opts.getLong(Pos.JitterDodge.SEED)
)

else -> throw IllegalArgumentException("Unknown position adjustments name: '$posName'")
Expand Down
8 changes: 4 additions & 4 deletions python-package/lets_plot/plot/pos.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def position_nudge(x=None, y=None):
return _pos('nudge', x=x, y=y)


def position_jitterdodge(dodge_width=None, jitter_width=None, jitter_height=None, jitter_seed=None):
def position_jitterdodge(dodge_width=None, jitter_width=None, jitter_height=None, seed=None):
"""
This is primarily used for aligning points generated through `geom_point()`
with dodged boxplots (e.g., a `geom_boxplot()` with a fill aesthetic supplied).
Expand All @@ -207,7 +207,7 @@ def position_jitterdodge(dodge_width=None, jitter_width=None, jitter_height=None
Jittering height.
The value of `jitter_height` is relative and typically ranges between 0 and 0.5.
Values that are greater than 0.5 lead to overlapping of the points.
jitter_seed : int
seed : int
A random seed to make the jitter reproducible.
If None (the default value), the seed is initialised with a random value.

Expand Down Expand Up @@ -238,11 +238,11 @@ def position_jitterdodge(dodge_width=None, jitter_width=None, jitter_height=None
stat='boxplot') + \\
geom_point(aes(x='c', y='x', color='c'), \\
size=4, shape=21, fill='white',
position=position_jitterdodge(jitter_seed=42))
position=position_jitterdodge(seed=42))

"""
return _pos('jitterdodge', dodge_width=dodge_width, jitter_width=jitter_width, jitter_height=jitter_height,
jitter_seed=jitter_seed)
seed=seed)


def position_stack(vjust=None, mode=None):
Expand Down