How to split a dataset and graph in R

I am using a dataset, for example:

1  48434  14566
1  56711  6289
1  58826  4174
2  56626  6374
2  58888  4112
2  59549  3451
2  60020  2980
2  60468  2532
3  56586  6414
3  58691  4309
3  59360  3640
3  59941  3059
.
.
.
10  56757  6243
10  58895  4105
10  59565  3435
10  60120  2880
10  60634  2366

I need a graph in R of the third column for each value of the first column, that is, for the above data there will be 10 different graphs (each group 1-10) of the values ​​of the third column. the x axis is the number of iterations, and the y axis is the values ​​with max 63000. I also need to connect the dots with red paint. I'm new to R and reading the documentation, but that bothers me more. can any body plz help.

EDIT: I really need a line graph of V3 values. the number of rows in column v3 will be along the x axis and v3 along the y axis. And I want different graphics for the group specified in v1. The Chase solution works, except that I want the axis to shift, the V3 values ​​should be on the y-axis. Here is an example alt text

EDIT2: @Roman, Here is the code that I am executing.

library(lattice)
d <- read.delim("c:\\proj58\\positions23.txt",sep="")
d <- do.call(rbind, lapply(split(d, d$V1), function(x) {
    x$iterations <- order(x$V3, decreasing=TRUE)
    x
}))
xyplot(V3 ~ iterations | V1, type="l", data=d)

, ,

    > 
>  source("C:\\proj58\\plots2.R")
> d
       V1    V2    V3 iterations
1.1     1 48434 14566          1
1.2     1 56711  6289          2
1.3     1 58826  4174          3
1.4     1 59528  3472          4

??? . , . ,

alt text

2 , V1 , 1,2,... -, , 100 , , (, ), ?

+3
3

, , . , , , .

, , , V1 ( ).

d <- do.call(rbind, lapply(split(d, d$V1), function(x) {
    x$iterations <- 1:nrow(x)
    x
}))
d$V1 <- factor(d$V1)

, lattice, -

xyplot(V3 ~ iterations | V1, type="l", data=d)

, layout. , , . , 5 5 :

trellis.device("pdf", file="myplot.pdf")
p <- xyplot(V3 ~ iterations | V1, type="l", data=d, layout=c(5,5))
plot(p)
dev.off()

, source, xyplot,

p <- xyplot(...)
plot(p)

, plot (, , print).

+2

, , , . , < lattice , , , .

library(lattice)
fdt <- data.frame(col1 = seq(from = 1, to = 10, each = 10),
        col2 = round(56 * rnorm(100, mean = 30, sd = 5)),
        col3 = round(20 * rnorm(100, mean = 11,)))
xyplot(col3 ~ 1:100 | col1, data = fdt)

alt text

+1

, , , , ... , .

: plyr ggplot2. plyr, , ggplot2 . pdf() .

library(ggplot2)
library(psych)    #For copying in data, not needed beyond that.

df <- read.clipboard(header = F)

pdf("test.pdf")
    d_ply(df, "V1", function(x)     #Split on the first column
        print(qplot(x$V3))          #Your plotting command should go here. This plots histograms.
    )
dev.off()                           #Close the plotting device.

This will lead to the creation of an n-page PDF, where n represents the number of groups in V1 (your split column). If you prefer JPEG outputs, look at? Jpeg or other graphics options to create other outputs.

EDIT: as you can see, people interpreted your question in several ways. If @Roman's solution is more than what you want, here is about the same ggplot code

qplot(col2, col3, data = fdt, geom = "point") + facet_wrap(~ col1 , nrow = 2)
0
source

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


All Articles