SPV -4 years ago 119
R Question

# How do I convert a plot into nodes? (Reduced representation)

What methods/algorithms can I utilize to convert the below plot into a series of nodes? I can use min and max for most of the nodes, but the main challenge I have is identifying the last plateau.
I am using R.

A quick example dataset that looks like mine would be a smoothed Nile dataset.

``````library(datasets)
ma <- function(x, n=5){ filter(x,rep(1/n,n), sides=2) }
plot(ma(Nile))
``````

Maybe you can tweak this approach:

``````library(strucchange)
bp <- breakpoints(V2~V1, data = df, h=3, breaks = 8)\$breakpoints
bp <- c(1, bp, nrow(df))
plot(df, type="l")
points(df\$V1[bp], df\$V2[bp], col="red", cex = 2)
``````

Data (via):

``````df <- structure(list(V1 = c(12.3, 12.6, 12.8, 12.8, 13.4, 13.1, 13.7,
13.4, 14, 14.3, 14.6, 16.1, 17.3, 18.7, 20.3, 20.9, 22, 23.1,
22.9, 23.1, 23.7, 24, 24.3, 24.6, 24.9, 25.1, 25.4, 25.7, 26,
26.3, 26.6, 26.9, 27.1, 27.4, 27.7, 28, 28.3, 28.6, 28.9, 29.4,
29.7, 30, 30.3, 30.6, 31.9, 32.6, 33.6, 34.2, 34.6, 34.9, 35.2,
35.4, 35.7, 36, 36.3, 36.6, 36.9, 36.9, 37.4, 37.4, 37.4, 37.7,
38, 38.3, 38.3, 38.6, 38.9, 39.2, 39.5, 39.7, 40, 40.3, 40.6,
40.9, 41.2, 41.5, 41.7, 42, 42.3, 42.7, 43.8, 44.3, 44.9, 45.2,
45.5, 45.7, 46, 46.3, 46.6, 46.9, 47.2, 47.5, 47.7, 48, 48.3,
48.6, 48.9, 49.2, 49.5, 49.8, 50, 50.3, 50.6, 50.9, 51.2, 51.5,
52.7, 53.6, 53.5, 54, 54.3, 54.6, 54.9, 55.2, 55.5, 55.8, 56,
56.3, 56.6, 56.9, 57.2, 57.5, 57.8, 58, 58.3, 58.6, 58.9, 59.2,
59.5, 59.8, 60, 60.3, 60.6, 60.9, 61.2, 61.5, 61.8, 62.1, 62.3,
63.1, 63.8, 64.3, 64.9, 65.2, 65.8, 65.9, 66.3, 67.5, 68, 68.6,
69.9, 70.9, 72.4, 73.2, 74.1, 75.4, 76.1, 77.9, 78.6, 78.8, 80.5,
80.9, 81.8, 83.2, 84.7, 86.2, 87.1, 87.8, 89.5, 90.5, 90.9, 92.2,
92.1, 93.5, 94.7, 94.4, 95, 95.2, 95.2, 96.1, 96.7, 97, 97.5,
97.8, 98.1, 98.1), V2 = c(25.4, 29.1, 33, 26.5, 36.9, 30.3, 39,
34.1, 40.8, 42.7, 44.2, 46.6, 46.9, 48.1, 48.7, 50.3, 51.1, 54,
52.4, 55.3, 56.9, 58.2, 60.1, 61.9, 63.4, 64.9, 66.3, 67.6, 69.4,
71.3, 73.3, 75.1, 76.7, 78.5, 80.2, 81.9, 83.5, 85.2, 86.5, 88.6,
90, 91.5, 92.8, 94.3, 96.2, 95.3, 93.3, 92.2, 89.9, 87.4, 84.9,
82.4, 79.8, 77.2, 74.6, 71.6, 68.4, 65.9, 62.4, 64.9, 60, 57,
59, 53.6, 56, 50.4, 47.3, 44.3, 41.6, 38.7, 36, 33.8, 31.8, 29.6,
27.8, 26.4, 25, 23.7, 22.5, 20.8, 21.7, 23.4, 25.5, 27.9, 30.2,
32.6, 35.3, 38, 40.7, 43.4, 46.1, 49, 51.8, 53.9, 56.2, 58.4,
60.5, 62.7, 64.9, 67, 69.1, 71.2, 73.1, 74.3, 75.5, 76.8, 78.7,
79.5, 78.2, 76.5, 74.9, 73, 71, 69, 67.1, 65.2, 63.3, 61.3, 59.7,
58.1, 56.7, 55, 53.3, 51.4, 49.5, 47.1, 44.8, 42.4, 40.8, 39.4,
38, 36.3, 34.4, 32.7, 31, 29.3, 27.6, 26, 25.1, 23, 22.4, 20.3,
19.5, 17.4, 16.7, 14.5, 13.2, 11.7, 10.8, 9.8, 7.9, 7.4, 4.8,
4.1, 5.1, 6.4, 7.5, 7.8, 8.4, 6.9, 7, 8.8, 9.2, 8.9, 7.8, 8.1,
6.7, 7.9, 8.2, 7, 6.4, 7.8, 6.4, 7.2, 10.6, 8.7, 13.2, 15.8,
18, 19.7, 21.4, 22.8, 24.7, 26.3, 27.8, 29)), .Names = c("V1",
"V2"), row.names = c(NA, -186L), class = "data.frame")
``````
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download