Zoom in and out for plot R

I know that a question has already been asked, but I could not solve my problem. I get a unreadale diagram when I select a text argument for my graph, and when I select an identification argument, it is not better.enter image description here

This is what I get from 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 could not add an identification argument and text ... I never used ggplot, so I do not know if it can solve my problem.

Thank you for your help.

+4
source share
1 answer

A tool that can help is facet_zoomfrom ggforce.

data.vehicule, mtcars data.frame .

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

+1

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


All Articles