# How to get individual plots in PDF

**URL:** <https://discourse.julialang.org/t/how-to-get-individual-plots-in-pdf/86415>\
**Category:** New to Julia\
**Tags:** plotting\
**Created:** [August 27, 2022, 5:00am UTC](https://discourse.julialang.org/t/how-to-get-individual-plots-in-pdf/86415 "2022-08-27T05:00:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sai\_matcha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sai_matcha/32/35801_2.png) [@sai\_matcha](https://discourse.julialang.org/u/sai_matcha)\
**Post date:** [August 27, 2022, 5:00am UTC](https://discourse.julialang.org/t/how-to-get-individual-plots-in-pdf/86415/1 "2022-08-27T05:00:13Z")

</div>

Hi.  
I am recently shifting from R to Julia. I want a help in getting individual plot for each ID in a PDF.  
I have attached the R code i used to do that. Can someone suggest equivalent code in julia to do the same?

```julia
pdf("path//indplots.pdf")
for(i in unique(df$ID))
{
  print((ggplot(subset(df,df$ID == i),aes(x=TAD,y=DV))+
           geom_point()+
           xlab("TAD (hrs)")+
           ylab("Plasma concentration (mg/L)")+
           ggtitle(paste(as.character(i)))+
           theme(panel.grid.minor=element_blank(),
                 panel.grid.major=element_blank(),
                 panel.background = element_blank(),
                 plot.title=element_text(hjust=0.5),
                 legend.position="right",
                 legend.key=(element_rect(colour='white',fill='white')),
                 plot.margin=unit(c(0.5,0.5,0.5,0.5),"cm"),
                 legend.text=element_text(colour="black",size=10),
                 axis.text.x=element_text(colour="black",size=10),
                 axis.text.y=element_text(colour="black",size=10),
                 axis.title=element_text(colour="black",size=14),
                 axis.line.x = element_line( colour="black",size=1,linetype ="solid"),
                 axis.line.y = element_line( colour="black",size=1,linetype ="solid"))))
}
dev.off()

```

Thanks in advance

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [August 27, 2022, 5:18am UTC](https://discourse.julialang.org/t/how-to-get-individual-plots-in-pdf/86415/2 "2022-08-27T05:18:59Z")

</div>

You got some suggestions in February. Could you expand on why those didn’t work for you?

> [@Create individual plot and save as pdf](https://discourse.julialang.org/t/create-individual-plot-and-save-as-pdf/76458):
>
> Hi … i used to use this code in r studio to generate individual plots for each id and save them as combined pdf for the offline evaluation. can someone help me to translate code to julia. pdf("path\\indplots.pdf") for(i in unique(df$ID)) { print((ggplot(subset(df,df$ID == i),aes(x=TAD,y=DV))+ geom\_point()+ xlab("TAD (hrs)")+ ylab("Plasma concentration (mg/L)")+ ggtitle(paste(as.character(i)))+ theme(panel.grid.minor=element\_blank(), …

To me it’s a bit difficult to help here, because you’re not describing clearly what you want. Do you want many pdf’s, one pdf with many pages or one pdf with one page with many plots?

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [August 27, 2022, 5:24am UTC](https://discourse.julialang.org/t/how-to-get-individual-plots-in-pdf/86415/3 "2022-08-27T05:24:20Z")

</div>

The documentation for PDFmerger.jl suggests this

```julia
using Plots, PDFmerger

for i in 1:5
    p = plot(rand(33), title="$i");
    savefig(p, "temp.pdf")
    append_pdf!("allplots.pdf", "temp.pdf", cleanup=true)
end

```

---

<div class="post-metadata">

**Author:** ![sai\_matcha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sai_matcha/32/35801_2.png) [@sai\_matcha](https://discourse.julialang.org/u/sai_matcha)\
**Post date:** [August 27, 2022, 6:19am UTC](https://discourse.julialang.org/t/how-to-get-individual-plots-in-pdf/86415/4 "2022-08-27T06:19:16Z")

</div>

My Dataframe looks like this

```julia
 df = DataFrame(id = 1:5, a = 10:14, b = 5:9)

```

I want pdf contains 5 pages.(1 page for 1 ID). i want a xy plot for the variables a and b.

10 on x , 5 on y for id 1 in first page,  
11 on x , 6 on y for id 2 in second page  
.  
.  
14 on x , 9 on y for id 5 in last page.

just plots for individual id’s.

is there a way to get that. Thank you

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [August 27, 2022, 9:52am UTC](https://discourse.julialang.org/t/how-to-get-individual-plots-in-pdf/86415/5 "2022-08-27T09:52:57Z")

</div>

```julia
for r in eachrow(df)
    p = plot([r.a], [r.b]; title="ID: $(r.id)", seriestype=:scatter)
    savefig(p, "temp.pdf")
    append_pdf!("plots.pdf", "temp.pdf"; cleanup=true)
end

```

Something like this?

---

<div class="post-metadata">

**Author:** ![sai\_matcha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sai_matcha/32/35801_2.png) [@sai\_matcha](https://discourse.julialang.org/u/sai_matcha)\
**Post date:** [August 27, 2022, 9:58am UTC](https://discourse.julialang.org/t/how-to-get-individual-plots-in-pdf/86415/6 "2022-08-27T09:58:02Z")

</div>

Exactly,Thank you very much.
