0

Hello everyone I´m trying to developed a plot with the next information:

x=c('La', 'Ce','Pr','Nd','Pm','Sm','Eu','Gd','Tb','Dy','Ho','Er','Tm','Yb','Lu')

utr=as.data.frame(t(nubtr))

V1        V2          V3        V4           V5         V6
1   431.223629  97.87928  609.913793 126.69584          Inf 111.486486
2  2214.209591 572.86432 2963.988920 455.69106 1130.0366300 231.250000
3   514.574899        NA          NA        NA   13.6704731  52.262931
4   144.967177       Inf  331.081081 923.62345  187.9396985 612.188366
5           NA        NA          NA        NA           NA         NA
6    54.810127  17.94454  108.297414  24.02626          Inf  34.527027
7    62.522202  16.98492   83.656510  13.49593   46.5201465  11.187500
8   442.510121  56.52174          NA        NA   12.3980424  57.758621
9     2.932166        NA    7.635135  22.38011    5.7788945  23.268698
10   27.154472 113.55311          NA        NA   41.7391304 229.674797
11    4.810127        NA          NA        NA          Inf   7.094595
12   53.108348  13.56784          NA        NA   63.5531136  17.812500
13   14.574899        NA          NA        NA    0.7830343   4.310345
14    5.295405       Inf   12.905405  38.01066   14.2211055  78.670360
15    1.178862        NA    1.681250  11.65992    2.4223602  16.260163

but I have a different length of x and y, so my question is how can a realize this kind of plot? The type of plot that I need is a scatterplot

Thank you so much Cheers

Dario
  • 1
  • 1
  • 1
    your question is unclear. Which object or column is the "y"? – Claudio Paladini Jan 25 '21 at 21:28
  • Welcome to SO! Please edit this question so that it contains a **minimal, reproducible example**, as detailed in this guide: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example Other users will have a difficult time answering your question if they can't replicate the exact same problem on their machines. – Captain Hat Jan 26 '21 at 00:34

1 Answers1

1

Here's a tidyverse option:

library(dplyr)
library(tidyr) # pivot_longer
library(ggplot2)
longdat <- tidyr::pivot_longer(utr, V1:V6, names_to="V", values_to="val") %>%
  mutate(val = if_else(!is.finite(val), NA_real_, val))
longdat
# # A tibble: 90 x 3
#    x     V        val
#    <fct> <chr>  <dbl>
#  1 La    V1     431. 
#  2 La    V2      97.9
#  3 La    V3     610. 
#  4 La    V4     127. 
#  5 La    V5      NA  
#  6 La    V6     111. 
#  7 Ce    V1    2214. 
#  8 Ce    V2     573. 
#  9 Ce    V3    2964. 
# 10 Ce    V4     456. 
# # ... with 80 more rows

ggplot(longdat, aes(x, val, color = V)) +
  geom_point(na.rm = TRUE)

ggplot2

r2evans
  • 141,215
  • 6
  • 77
  • 149