0

I am trying to create some lines on a graph based on a third coordinate (x,y, temp). I would like to get a vector of indexes so I can split them into x and y vectors for each duplicate temperature. To make this more clear, I will include my actual data set:

DataFrame

I am trying to make multiple lines that have the same temp value. For example, I would like to have the following coordinates on the same line [0,14] [0,22] [0,26] [0,28]. They all have the temp value of 5.8. Once I find the duplicates, I will record the indexes in a vector which will allow me to retrieve the x and y coordinates. One other aspect is that I will not always know how many entries are going to be in the data.frame.

My question is how can I find the duplicates and store their indices in a vector? Once I have the indices for the duplicate temps, I can be sure to grab their x y coordinates and use that to create lines. If you can answer my question or have any advice on how I can do this better, all help is appreciated

DaDuStMaN20
  • 137
  • 2
  • 11
  • What you're asking is quite complex. It would help if you gave an example of the output that you want for an example input. – Ryan C. Thompson Oct 31 '16 at 21:00
  • The input would be a data frame (I can handle the input) the output would be a graph with multiple lines on it. each line is based on one "temp" value. It is going to be an Isopleth graph for use in the environmental science field – DaDuStMaN20 Oct 31 '16 at 21:05
  • @coffeinjunky the DataFrame Link at the bottom links to an image of part of the data set. I cannot embed images yet. – DaDuStMaN20 Oct 31 '16 at 21:08
  • Please see here for some advice on how to share data with StackOverflow: http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – coffeinjunky Oct 31 '16 at 21:13

2 Answers2

0

Consider the following:

df <- data.frame(temp = sample.int(n=3, size=5, replace=T))
df
  temp
1    3
2    3
3    1
4    3
5    1

duplicated(df$temp)
[1] FALSE  TRUE FALSE  TRUE  TRUE

which(duplicated(df$temp))
[1] 2 4 5
coffeinjunky
  • 11,254
  • 39
  • 57
0

You've stated in the comments that you're looking to make an isopleth graph. The procedure you have described will not generate anything resembling an isopleth graph. Since it looks like your data is arranged in a regular grid, you should do something like the solutions presented in this question and answer, which use functions specifically designed for extracting contours from a grid of values. Another option is the contourLines function in the gDevices package. If you want higher-resolution, less jagged contours, you might look into using either the interp.surface or Krig functions from the fields package to interpolate your data to the resolution you require.

Community
  • 1
  • 1
Ryan C. Thompson
  • 40,856
  • 28
  • 97
  • 159
  • I am not a scientist, so I got an example graph. I was told that it was an isopleth graph. The scientist was surveying the temperature of a pond. The x coordinate was the distance they went from the one side of the pond, they y-coordinate was the depth that they measured the temperature at, and the temp is the temperature at that depth. The scientist wants to have lines that connect the points where the temperatures are the same. If you would like, I can put a picture of an example graph from the scientist. – DaDuStMaN20 Oct 31 '16 at 21:32
  • I understand the type of plot you are describing. However, drawing isopleths is not a matter of simply playing connect-the-dots. There are special purpose functions available for *correctly* generating and plotting contour lines (i.e. isopleths), which I've linked to in my answer. – Ryan C. Thompson Oct 31 '16 at 21:35