Giter Site home page Giter Site logo

desplot's People

Contributors

kwstat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

desplot's Issues

on making ggdesplot more complete

I understand that ggdesplot() is incomplete and will probably always remain a sort of younger step-sibling of desplot(). In general, I am fine with that and have been using desplot() happily for a while now.

However, I noticed that in some situations I do wish that the created plots would be ggplot objects (, though I realize this may just be because of my subjective preference or rather personal knowledge gap between lattice and ggplot2). Basically, it comes down to the following aspects:

  • fine-tuning the legend, which I addressed in #3 but so far couldn't find a solution for
  • arranging multiple plots (e.g. via cowplot) and in an RMarkdown framework.

Because of this, I tried having a look at the source code to see if I can be of any help improving it. Ultimately, my question is whether you could use suggestions such as the small one I made below to potentially improve ggdesplot() or not.

Enforce `nrow = 1` with `|location`?

With my current desplots, the visual information gain when including |block for blocks within a single trial is great. However, when it comes to exporting the graph I usually run into the blocks being shown in multiple rows of the plot. Is there a hack to force them to all be on the same row?

library(tidyverse)
library(desplot)

dat <- tibble::tribble(
  ~row, ~col, ~rep, ~id,
  1L,   1L,   1L, "A",
  2L,   1L,   1L, "B",
  1L,   2L,   2L, "B",
  2L,   2L,   2L, "A",
  1L,   3L,   3L, "B",
  2L,   3L,   3L, "A",
  1L,   4L,   4L, "B",
  2L,   4L,   4L, "A",
)

desplot(dat, 
        id ~ col + row,
        text = id, cex = 1)

desplot(dat, 
        id ~ col + row | rep,
        text = id, cex = 1)

Created on 2022-02-11 by the reprex package (v2.0.1)

Most elegant way to reduce legend?

Quite often I would like to have a legend that explains colors (region and col =) but not the text =. I admit that this is because I often use two of them for the same purpose/factor. Here is an example:

grafik

I am guessing that there might be a rather tidy way to fix this, but I am not sure where to start.

position of first plot

Dear developers

How can I get the first plot to be shown in the left upper corner?
As input I've got rows (r). columns (c) and for the text the plot numbers (plot) and the colours representing the residuals (res) of a disease score.

desplot(experiment1, res ~ c + r, text = plot, cex = 0.5, gg = T, col.regions = c("maroon", "gray97","slateblue"), 
main = "some title text")

At the moment the graph is upside down with plot 1 in the left lower corner. (Title edited out.)
testgraph

Many thanks,

A Webb

num= argument does not support negative numbers and decimal places

In Example 2 of the 'desplot' vignette, a heatmap of residuals is plotted. Changing the text=gen statement to num=res in order to plot the actual values, shows a '1' in the plot that actually has a residual of '-1'.

library(agridat); library(desplot)
nuts <- ryder.groundnut
mod <- lm(data=nuts, formula= dry ~ block + gen)
nuts$res <- resid(mod)
desplot(data=nuts, form= res ~ col+row, num=res, show.key=F, main="")

grafik

Furthermore, plotting the yield data of e.g. the john.alpha dataset in the agridat package leads to plotted values that simply seem to ignore the decimal point and therefore seem to disagree with the ribbon.

library(agridat); library(desplot)
alpha<- john.alpha
alpha$row <- rep(4:1)
alpha$col <- sort(rep(seq(18:1),4))
desplot(data=alpha, form= yield ~ col+row, num=yield, show.key=F, main="")

grafik

Unnecessary warning for tibble formatted data objects?

Hi,
I have recently been getting this warning whenever I supply a tibble to the data = argument.

## Warning in if (class(data) == "formula") {: the condition has length > 1 and only
## the first element will be used

Notice that this warning disappears if I write data = as.data.frame(tibble).

Removing White Space

Hi, in the reprex below I show how I usually get rid of white space / empty areas in certain desplots. I simply want to ask: Is this optimal or would you recommend a different approach? Especially the c(0.6, 1.4) seems arbitrary to me.

library(desplot)
library(tidyverse)

dat <- tibble(
  var = letters[1:6],
  block = as.factor(c(1, 1, 1, 2, 2, 2)),
  row = 1L,
  col = 1:6
)

d <- desplot(data = dat,
             form = var ~ col + row | block)

d

update(d, ylim = c(0.6, 1.4))

Created on 2022-12-22 with reprex v2.0.2

Using `| location` for reps with incomplete data

Hi, I just realized that x/y coordinates missing in the data are treated differently depending on whether I use the | location argument or not:

library(tidyverse)
library(desplot)

dat <- tibble::tribble(
  ~row, ~col, ~rep, ~id,
    1L,   1L,   1L, "A",
    2L,   1L,   1L, "B",
    1L,   2L,   2L, "C",
    2L,   2L,   2L, "D",
    3L,   2L,   2L, "E"
  )

desplot(dat, 
        id ~ col + row,
        text = id, cex = 1)

desplot(dat, 
        id ~ col + row | rep,
        text = id, cex = 1)

I guess this is intended (?), given that the | location suggests using this argument for different trials (where it makes sense) and not multiple replicates of the same trial as I am doing here.
However, if I do want to use it for reps of the same trial, then there is no extra argument to make this work, right? I would simply need to add the missing lines of data to the dataset, i.e. have all x-y-combinations as NA present. I realize how odd it is in the first place to have field trial data that includes only a subset of all plots, but that's what I received in this case.

Here's the solution I came up with:

datexp <- expand_grid(
  row = 1:max(dat$row),
  col = 1:max(dat$col)
) %>% 
  left_join(y = dat, by = c("row", "col")) %>% 
  mutate(rep = col)

desplot(datexp,
        id ~ col + row | rep,
        text = id, cex = 1)

Created on 2022-02-04 by the reprex package (v2.0.1)

Potentially misleading error about duplicate cells

The first desplot complains about multiple data for each x/y/panel.
The second desplot does not.
I suspect the check for multiple cells is not able to handle two terms in year*site.

  library(agridat)
  data(tesfaye.millet)
  dat <- tesfaye.millet

  libs(desplot)
  dat <- transform(dat, year=factor(year), site=factor(site))
  desplot(dat, yield ~ col*row|year*site, out1=rep, main="tesfaye.millet")
# Warning message:
# In desplot(dat, yield ~ col * row | year * site, out1 = rep, main = "tesfaye.millet") :
# There are multiple data for each x/y/panel combination

  libs(dplyr,asreml,lucid)
  dat <- mutate(dat,
                env=factor(paste0(site,year)),
                gen=factor(gen),
                rep=factor(rep),
                xfac=factor(col), yfac=factor(row))
  desplot(dat, yield~col*row|env)

Named vector for `col.regions` and `col.text`

In ggplot() I can use a named vector (where the values are colors and the names are the respective levels) e.g. in scale_color_manual(values = ... ) and it will correctly draw colors per level no matter in which order the levels appear in the data vs. the named vector. If I understand correctly, this does not apply for col.regions = and col.text = in desplot(). Instead, colors must be provided in the same order as the levels in the data.

Am I correct and do you find it worthwhile implementing this suggestion?

Here is an example where I try using a named vector that is sorted in the wrong order and it leads to a mismatch between colors and levels:

require(agridat)
require(desplot)

gen_cols <- c("blue", "gray", "orange")
names(gen_cols) <- rev(levels(yates.oats$gen)) # rev()!

gen_cols
#>    Victory Marvellous GoldenRain 
#>     "blue"     "gray"   "orange"

desplot(
  yates.oats,
  gen ~ col + row,
  col.regions = gen_cols,
  col = nitro,
  text = gen,
  cex = 1,
  aspect = 511 / 176,
  out1 = block
)

Created on 2023-06-13 with reprex v2.0.2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.