Zoom in and zoom out for R graph

2.3k views Asked by At

I know the question was already asked, but i couldn't solve my problem. I get a graph unreadale when i choose the text argument for my graph and when i choose the identify argument it's not better.enter image description here

This is what i get whith this script :

VehiculeFunction <- function(data, gamme, absciss, ordinate, label, xlim, ylim){
  my.data <- data[data$GAMME == gamme,]
  ma.col = rgb(red = 0.1,blue = 1,green = 0.1, alpha = 0.2)
  X <- my.data[[absciss]] 
  Y <- my.data[[ordinate]] 
  Z <- my.data[[label]]
  X11()
  plot(X, Y, pch=20, las = 1, col = ma.col, xlab = absciss, ylab = ordinate, xlim = xlim, ylim = ylim)
  text(X, Y, labels = Z, pos=3, cex = 0.7, col = ma.col)
  #identify(X, Y, labels = Z, cex = 0.7)
}

VehiculeFunction(data.vehicule, "I", "GMF.24", "Cout.24", "NITG", c(0,0.2), c(0,0.2)) 

I used iplot, but i couldn't add the identify and text argument... I never used ggplot, so i don't know if it's could solve my problem.

Thank you for help.

1

There are 1 answers

0
Peter On

A tool that might help with is facet_zoom from the ggforce package.

I don't have access to the data.vehicule object, so I will use the mtcars data.frame for an example of zooming in on a region of the graphic.

library(ggplot2)
library(ggforce)
library(dplyr)

mtcars2 <- mtcars %>% mutate(nm = rownames(mtcars))

ggplot(mtcars2) +
  aes(x = wt, y = mpg, label = nm) +
  geom_text()

last_plot() +
  theme_bw() +
  facet_zoom(x = dplyr::between(wt, 3, 4),
             y = dplyr::between(mpg, 12, 17))

enter image description here