I am trying to understand how to use ggstructure
in ggplot2. Using the documentation examples, I can successfully get the example code to work: ggstructure(mtcars)
. However, I can not get ggstructure to produce any plot from my own data read in from file. For example:
My data looks like this:
colors,hue,saturation,vibrance
BLUE,10,2,100
RED,2,86,2
GREEN,45,23,11
My code looks like this:
library(ggplot2)
data <- read.table("/path/to/data", head=TRUE, sep=",')
ggstructure(data)
When I try to plot with ggstructure
I get
Error: Non-continuous variable supplied to scale_fill_gradient2.
In addition: Warning messages:
1: In `[<-.factor`(`*tmp*`, ri, value = c(1L, 3L, 2L, NA, NA, NA)) :
invalid factor level, NAs generated
2: In `[<-.factor`(`*tmp*`, ri, value = c(1L, 3L, 2L, NA, NA, NA, NA, :
invalid factor level, NAs generated
3: In `[<-.factor`(`*tmp*`, ri, value = c(1L, 3L, 2L, NA, NA, NA, NA, :
invalid factor level, NAs generated
I also tried to change the data to continuous, but this produced the same problem. Can anyone help? Thanks.
Looking at the code, it doesn't appear that ggstructure
(which is just a wrapper for ggpcp
) was really intended to be used with non-continuous data.
The parallel coordinates plot function ggpcp
attempts to rescale and then melt the entire data set. This results in a single y
variable, grouped by the "variables" in the original data set. If you have a mix of continuous/categorical variables, this means this will be coerced to a factor, and how you plot it suddenly isn't clear.
Short version is if you have a mix of continuous/categorical variables, you'll have to cook something up yourself, I think.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.