-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"contour"
#218
Comments
We could use Quick proof of concept that also uses that 'nested' ID coloring approach mentioned in #41 (comment) (contour plots are another case where this nesting would be necessary). library(tinyplot)
cl = contourLines(z = volcano)
cl = lapply(cl, as.data.frame)
cl = do.call(rbind, unname(Map(cbind, id = seq_along(cl), cl)))
head(cl)
#> id level x y
#> 1 1 100 1.0000000 0.5515289
#> 2 1 100 0.9883721 0.5515289
#> 3 1 100 0.9778109 0.5666667
#> 4 1 100 0.9767442 0.5681956
#> 5 1 100 0.9651163 0.5681956
#> 6 1 100 0.9545551 0.5833333
cols = with(cl, tapply(factor(level), id, FUN = `[[`, 1)) # grab group colours
plt(
y ~ x | id, cl,
type = "l",
col = hcl.colors(length(unique(cols)))[cols],
legend = FALSE
)
#> Warning in tinyplot.default(x = x, y = y, by = by, facet = facet, facet.args = facet.args, :
#> Continuous legends not supported for this plot type. Reverting to discrete legend. Filled contour plots would take a bit more thinking; the below doesn't work properly because of sub-optimal joins of the 'outer' polygons that should really extend into the plot margin. Also: each polygon should be drawn in 'donut' fashion—with the hole determined by the next contour—rather than filling in all the interior space. plt(
y ~ x | id, cl,
type = "polypath", #rule = 'evenodd',
col = hcl.colors(length(unique(cols)))[cols],
legend = FALSE, fill = 0.1
)
#> Warning in tinyplot.default(x = x, y = y, by = by, facet = facet, facet.args = facet.args, :
#> Continuous legends not supported for this plot type. Reverting to discrete legend. Created on 2024-09-16 with reprex v2.1.1 |
Good idea. I'm not fully clear though whether you already expect to have some sort of three-dimensional data already (x and y coordinates plus height/levels) or whether it should be two-dimensional. The latter would conceptually be straightforward but necessitate (a) new type(s) of plot, e.g., For three-dimensional data like the |
All valid points! I haven't had time to think about it much, just wanted to jot down a quick proof of concept. You're absolutely right that the implementation would require some thought w.r.t. user interface. (Doesn't lattice have a contour method that might give us some ideas for potential formula logic?) |
Good point. In For the
Or you can set up a data frame with three variables like this:
And then you can use the formula interface:
If you additionally set In short, I guess this is closer to what you had in mind, right? The plots I was looking for (smoothed scatterplots for 2d data) could then possibly be accomplished by deriving the density estimate and then calling the 3d functionality. |
Just a link so that I don't forget. It's not about contours but about heatmaps which we also mentioned above. Maybe this is useful for inspiration (maybe not): https://jbengler.github.io/tidyheatmaps/ |
No description provided.
The text was updated successfully, but these errors were encountered: