1

First of all, I'm sorry for my bad English.

I need to link some ids to graphs that I make dynamically with a loop in R.

The code below is just an example but it can show the problem.

Basically I have to make a lot of graphs by a loop (or other form that you can suggest) and I know that some ids have problems.

My goal is put a list at the start of the document with these ids linked to the correct graph.

Is there somehow to do that?

Thanks in advance.

---
title: "Untitled"
author: "nanopuntouy"
date: "6 de noviembre de 2015"
output: html_document
---

I have a list of numbers here that I know which have troubles, for example: 

- 2

- 18 

- 134


How can I link these numbers to the appropriate graph, if I'm making 150 graphs?


```{r, echo=FALSE}

data=iris

data$ID=as.numeric(row.names(data))


for(i in data$ID){
  if(i==2 | i==18 | i==134) print("SOMETHING SPECIAL???") 
  print(i)
  ## Do something. All the graphs are identical. it's just an example
  hist(data$Sepal.Length, main=i) 
}


```
#

Finally I could solve this problem adding anchors and links. I had to add the argument "results='asis'" and "fig.alig='center'" into the chunk in order to get a good result.

Then in the loop we put a conditional like this:

if(i==2 | i==18 | i==134) print(paste("<a name=\"",i,"\"></a>",sep=""),quote = F)

and it works. Maybe it's not the best way to do that but it worked for me.

Bellow the final code:

---
title: "Untitled"
author: "nanopuntouy"
date: "6 de noviembre de 2015"
output: html_document
---

I have numbers here that I kwon which have troubles, for example: 

- [2](#2)

- [18](#18) 

- [134](#134)


How can I link these numbers to the appropriate graph, if I'm making 150 graphs?


```{r, echo=FALSE, results='asis',fig.align='center'}

data=iris

data$ID=as.numeric(row.names(data))


for(i in data$ID){
  if(i==2 | i==18 | i==134) print(paste("<a name=\"",i,"\"></a>",sep=""),quote = F)
  print(i)
  ## Do something. All the graphs are identical. it's just an example
  hist(data$Sepal.Length, main=i) 
}


```

0 Answers0