Getting jitter in ggplotly

I'm trying to get on a plot plot with phase axes, adding a jitter to the readability values.

I can get the desired effect in ggplot2, but when I try to wrap it with a graph, jitter doesn't do it. Any way to make this work?

An example of what is happening. The g below looks correct, but p then loses its jitter.

data<-data.frame(cbind(
  sample(c('level 1', 'level 2', 'level 3'), 100, replace = TRUE),
  sample(c('level 1', 'level 2', 'level 3', 'level 4'), 100, replace = TRUE)))

names(data)<-c('factor1', 'factor2')

g <- ggplot(data, aes(x=factor1, y=factor2)) 
g <- g + geom_point(position = position_jitter(w = 0.2,h = 0.2))
#g <- g + geom_jitter(width = .2, height = .2)
g <- g +xlab('Category One')
g <- g +ylab('Category Two')

g

p <- ggplotly(g)
p
+4
source share
2 answers

Perhaps there is work. Replace your coefficient with an integer and replace it after.

data<-data.frame(cbind(
    sample(1:3, 100, replace = TRUE),
    sample(1:4, 100, replace = TRUE)))

names(data)<-c('factor1', 'factor2')

g <- ggplot(data, aes(x=factor1, y=factor2)) 
g <- g + geom_point(position = position_jitter(w = 0.2,h = 0.2)) + scale_x_continuous("Factor 1", breaks = c(1,2,3)) + scale_y_continuous("Factor 2", breaks = c(1,2,3,4))
ggplotly(g)

relabel x and y ticks

x <- list(
  tickprefix = "Level"
)

y <- list(
  tickprefix = "Level"
)

g %>% layout(xaxis = x, yaxis = y)

enter image description here

+3
source

It works:

data<-data.frame(cbind(
  sample(1:3, 100, replace = TRUE),
  sample(1:4, 100, replace = TRUE)))

names(data)<-c('factor1', 'factor2')

g <- ggplot(data, aes(x=factor1, y=factor2)) 
g <- g + geom_point(position = position_jitter(w = 0.2,h = 0.2)) + scale_x_continuous("Factor 1", breaks = c(1,2,3)) + scale_y_continuous("Factor 2", breaks = c(1,2,3,4))
p <- ggplotly(g)

x <- list(title = "Category One",tickmode = "array",tickvals = c(1,2,3) , ticktext = c("A", "B", "C"))
y <- list(title = "Category Two",tickmode = "array",tickvals = c(1,2,3,4) , ticktext = c("A", "B", "C", "D"))

p <- p %>% layout(xaxis = x, yaxis = y)
p
-1
source

Source: https://habr.com/ru/post/1628317/


All Articles