using ggplot2 with data.table to produce multiple .pdfs produces all data on each plot

iembry

I have the same example as before (interpolation of grouped data using data.table), but here I am trying to use ggplot2 to create a single .pdf plot for each site_no. Instead of the data for each site_no printed on a single .pdf, all of the data from all of the plots are printed on each site_no named .pdf. Can you assist?

Thank you.

Irucka

library(data.table)
library(ggplot2)

tempbigdata1 <- data.table(c(14.80, 14.81, 14.82), c(7900, 7920, 7930),      c("02437100", "02437100", "02437100"))

tempbigdata2 <- data.table(c(9.98, 9.99, 10.00), c(816, 819, 821), c("02446500", "02446500", "02446500"))

tempbigdata3 <- data.table(c(75.65, 75.66, 75.67), c(23600, 23700, 23800), c("02467000", "02467000", "02467000"))

tempsbigdata <- rbind(tempbigdata1, tempbigdata2, tempbigdata3)

setnames(tempsbigdata,c("depth", "discharge", "site_no"))

setkey(tempsbigdata, site_no)

tempsbigdata
depth       discharge   site_no
1: 14.80    7900        02437100
2: 14.81    7920        02437100
3: 14.82    7930        02437100
4:  9.98    816         02446500
5:  9.99    819         02446500
6: 10.00    821         02446500
7: 75.65    23600       02467000
8: 75.66    23700       02467000
9: 75.67    23800       02467000

ratingsplot <- tempsbigdata[,list(discharge,depth),by=site_no]

for (u in unique(ratingsplot$site_no)) {pdf(file = file.path("/plots/",   paste0(u, "_rating.pdf", sep = "")))
p <- ggplot(ratingsplot, aes(x = discharge, y = depth, group = site_no))
print(p <- p + geom_point() + theme_bw())
dev.off()
}  
IRTFM

Try modifying the data argument to ggplot(ratingsplot[site_no==u],...

 p <- ggplot(ratingsplot[site_no==u], 
             aes(x = discharge, y = depth, group = site_no))

Other plotting paradigms have a subset argument that accepts a logical expression interpreted in the environment of the data argument, but I didn't see one documented or linked to from the `?ggplot help page.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Combining multiple data frames in one plot using ggplot2

分類Dev

Plot multiple data using for loop, pyplot and genfromtxt

分類Dev

Line Plot subset data with ggplot2 (facet)

分類Dev

Data scraping: How to read all table content from multiple pages (using next page)?

分類Dev

How to plot multiple time series with a reverse barplot on the secondary axis using ggplot2?

分類Dev

Trying to display all data from database table into Jtable using reflection

分類Dev

rolling average to multiple variables in R using data.table package

分類Dev

matplotlib - multiple markers for a plot based on additional data

分類Dev

will 'val' produce mutable data?

分類Dev

Plot multiple ROC curves with ggplot2 in different layers

分類Dev

how to plot multiple area plots with ggplot2?

分類Dev

Search data from multiple table

分類Dev

multiple data sources to one table

分類Dev

Retrieving data from table 1 using table 2 in the order of table 2 data

分類Dev

Can I plot a percentage of subcategory in ggplot without summarizing a long format data table?

分類Dev

Add other series to panel/facet plot using ggplot2

分類Dev

I need specific table data for each users

分類Dev

Rails: each for multiple and one object data

分類Dev

How to filter a data table with each items in a object using RowFilter in c#

分類Dev

Display table data using angularjs

分類Dev

Data table aggregation and using toString()

分類Dev

Left join using Data Table

分類Dev

laravel pivot table return all related data

分類Dev

Extract all data between multiple vertical bars

分類Dev

ggplot2 add separate legend each for two Y axes in facet plot

分類Dev

Laravel: How to query data from multiple table?

分類Dev

Multiple conditions for r data.table calculation

分類Dev

r data table subset multiple conditions patterns

分類Dev

Plotting multiple lines on a single graph using Shiny and ggplot2

Related 関連記事

  1. 1

    Combining multiple data frames in one plot using ggplot2

  2. 2

    Plot multiple data using for loop, pyplot and genfromtxt

  3. 3

    Line Plot subset data with ggplot2 (facet)

  4. 4

    Data scraping: How to read all table content from multiple pages (using next page)?

  5. 5

    How to plot multiple time series with a reverse barplot on the secondary axis using ggplot2?

  6. 6

    Trying to display all data from database table into Jtable using reflection

  7. 7

    rolling average to multiple variables in R using data.table package

  8. 8

    matplotlib - multiple markers for a plot based on additional data

  9. 9

    will 'val' produce mutable data?

  10. 10

    Plot multiple ROC curves with ggplot2 in different layers

  11. 11

    how to plot multiple area plots with ggplot2?

  12. 12

    Search data from multiple table

  13. 13

    multiple data sources to one table

  14. 14

    Retrieving data from table 1 using table 2 in the order of table 2 data

  15. 15

    Can I plot a percentage of subcategory in ggplot without summarizing a long format data table?

  16. 16

    Add other series to panel/facet plot using ggplot2

  17. 17

    I need specific table data for each users

  18. 18

    Rails: each for multiple and one object data

  19. 19

    How to filter a data table with each items in a object using RowFilter in c#

  20. 20

    Display table data using angularjs

  21. 21

    Data table aggregation and using toString()

  22. 22

    Left join using Data Table

  23. 23

    laravel pivot table return all related data

  24. 24

    Extract all data between multiple vertical bars

  25. 25

    ggplot2 add separate legend each for two Y axes in facet plot

  26. 26

    Laravel: How to query data from multiple table?

  27. 27

    Multiple conditions for r data.table calculation

  28. 28

    r data table subset multiple conditions patterns

  29. 29

    Plotting multiple lines on a single graph using Shiny and ggplot2

ホットタグ

アーカイブ