high dimensional plot

Hello :slight_smile:

I want to plot something that looks somewhat like this
[http://www.sthda.com/sthda/RDoc/figure/ggplot2/ggplot2-line-plot-customized-line-graph-data-visualization-1.png]

with my data set i get the Error: "Discrete value supplied to continuous scale" when i take the "T" column as my "y" axis (this is what i orginally thought would i be able to do)
i checked 3 other threads that already treat the "same" issue

  1. https://community.rstudio.com/t/error-discrete-value-supplied-to-continuous-scale-on-rstudio/45586/3
  2. https://community.rstudio.com/t/understanding-when-and-why-discrete-value-supplied-to-continuous-scale-happens/26011/2
  3. https://community.rstudio.com/t/plotting-multiple-lines-gives-error-discrete-value-supplied-to-continuous-scale/39752/4

unfortunately i cannot make by "T" column as numeric and the other suggestions are not close to what i want to to with my data
snapshop of my data:
@andresrcs thanks for the reminder :slight_smile:

tibble::tribble(
~schaetz_m, ~m_unt, ~m_ob,    ~T, ~Date,        ~schaetz_g, ~g_unt, ~g_ob,
-1.20,      -1.27,   -1.13,  a_a, "2019-07-04", -0.89,     -0.98,   -0.79,
-0.34,      -0.49,   -0.19,  c,   "2019-07-04", -0.38,     -0.55,   -0.21,
-0.77,      -0.92,   -0.63,  d_d, "2019-07-04", -0.50,     -0.68,   -0.32,
 0.50,       0.25,    0.75,  a_a, "2019-09-06",  0.20,      0.01,    0.40,
-0.95,      -1.20,   -0.70,  c,   "2019-09-06", -1.37,     -1.64,   -1.09,
-1.20,      -1.37,   -1.03,  d_d, "2019-09-06", -0.78,     -0.93,   -0.63,
 0.91,       0.79,    1.03,  a_a, "2019-10-13",  0.96,      0.81,    1.10,
-0.80,      -0.94,   -0.67,  c,   "2019-10-13", -0.53,     -0.70,   -0.41,
-0.75,      -0.93,   -0.56,  d_d, "2019-10-13", -1.19,     -1.31,   -1.08,
)
#> Error in list2(...): object 'a_a' not found

Created on 2020-03-11 by the reprex package (v0.3.0)
@andresrcs does that work? my actual data.frame has 140 rows
my code

visualization <- ggplot(data, aes(x=Date, y=schaetz_m, group = T))+ 
  geom_errorbar(aes(ymin=m_unt, ymax=m_ob), width=.1, 
                position=position_dodge(0.05)) +
  geom_line(aes(x=Date, y=schaetz_g)) + 
  geom_point()+
  labs(title="Plot123",x="Date", y = "Name")+
  theme_classic()
p + theme_classic() + scale_color_manual(values=c('#999999','#E69F00'))

with this i get a very unsatisfying plot
Rplot03
in the end i want to have all of the information of the dataset in one or maybe a paired plot

i want the following information in the plot:

  1. as you can see the T values repeat themselves. i want two lines for each of them. one taking the value of the "schaetz_m" column and the other the value of the "schaetz_g" column (with different colour?/shape?)
  2. i want to have them labelled with their values as in column "T"
  3. (optional) i want to have additional lines/point/shapes/boxplot-like-objects that represent the information of all the other columns (which are not standard deviation, but otherwise related to the main lines "schaetz_m" and "schaetz_g")

I hope you can understand what i am imagining. I think i it very helpful to look at the following link, which captures already most of what i want to visualize with my data., except i will have more lines that this example:
http://www.sthda.com/sthda/RDoc/figure/ggplot2/ggplot2-line-plot-with-error-bar-data-visualization-1.png

Thanks a lot and i hope i was clear enough. dont hesitate to ask if you couldnt couldnt follow. sorry for my basic english. :slight_smile:

Can you post the actual code for your data instead of a screenshot?, we can't copy from that.

Re the error at the bottom of your tribble() code: For ease of copying, you should onvert the content of your 'T' column to strings.

I think you may want the table in the following form:

tribble(
~ Date, ~ T, ~ shaetz_type, ~ shaetz_value, ~ unt, ~ob
)

You can use the pivot_longer() and pivot_wider() commands for this -- do you know them?

@dromano thank you for making me aware of the pivot_longer() and pivot_wider() functions. i didnt know them and wasnt able to work with them (yet) but the description sounds very useful, especially with my data. i didnt use the pivot_longer() or pivot_wider() functions but in the end i got the format you asked me to have

tibble::tribble(
  ~schaetzung, ~unterer,    ~oberer,     ~Team, ~Datum,       ~schaetz_type,
  -1.20600722, -1.27406046, -1.13795403, "BE", "2019-09-04",    "m",
  -0.34178830, -0.49025695, -0.19332039, "SG", "2019-09-04",    "m",
  -0.77783117, -0.92155665, -0.63410838, "HM", "2019-09-04",    "m",
  -0.87023609, -0.95052642, -0.78996492, "LS", "2019-09-04",    "m",
   0.82741911,  0.71214397,  0.94205678, "SS", "2019-09-04",    "m",
   1.01777813,  0.91384768,  1.12461777, "PK", "2019-09-04",    "m",
   1.35778070,  1.20020542,  1.43455935, "RK", "2019-09-04",    "m",
  -0.89140967, -0.89352401, -0.79346693, "BE", "2019-09-04",    "g",
  -0.38676828, -0.55602560, -0.21751113, "SG", "2019-09-04",    "g",
  -0.50074202, -0.68063002, -0.32085244, "HM", "2019-09-04",    "g",
  -1.33333247, -1.40421368, -1.26241880, "LS", "2019-09-04",    "g",
   0.92697903,  0.81628041,  1.03717525, "SS", "2019-09-04",    "g",
   1.42290811,  1.34166203,  1.50219959, "PK", "2019-09-04",    "g",
   0.76853563,  0.68806555,  0.88419067, "RK", "2019-09-04",    "g",
   0.50713972,  0.58928908,  0.75534955, "BE", "2019-09-06",    "m",
  -0.95816018, -1.20883898, -0.70749798, "SG", "2019-09-06",    "m",
  -1.20572109, -1.37890104, -1.03340317, "HM", "2019-09-06",    "m",
   0.31418804, -0.00164114,  0.62999249, "LS", "2019-09-06",    "m",
  -0.35742292, -0.62883711, -0.11355746, "SS", "2019-09-06",    "m",
   1.87457744,  1.82436404,  2.06671846, "PK", "2019-09-06",    "m",
  -0.15417069, -0.58044760,  0.27210654, "RK", "2019-09-06",    "m",
   0.20285233,  0.00058871,  0.40511577, "BE", "2019-09-06",    "g",
  -1.37138008, -1.64445563, -1.09827060, "SG", "2019-09-06",    "g",
  -0.78744117, -0.93569569, -0.63888539, "HM", "2019-09-06",    "g",
   0.36839513,  0.10252459,  0.63166502, "LS", "2019-09-06",    "g",
  -0.32984756, -0.52593982, -0.13643571, "SS", "2019-09-06",    "g",
   1.91653954,  1.73966018,  2.12911299, "PK", "2019-09-06",    "g",
   0.09466097, -0.73383450,  0.46270508, "RK", "2019-09-06",    "g",
   0.91490866,  0.72448529,  1.03736747, "BE", "2019-09-07",    "m")
#> # A tibble: 29 x 6
#>    schaetzung unterer oberer Team  Datum      schaetz_type
#>         <dbl>   <dbl>  <dbl> <chr> <chr>      <chr>       
#>  1     -1.21   -1.27  -1.14  BE    2019-09-04 m           
#>  2     -0.342  -0.490 -0.193 SG    2019-09-04 m           
#>  3     -0.778  -0.922 -0.634 HM    2019-09-04 m           
#>  4     -0.870  -0.951 -0.790 LS    2019-09-04 m           
#>  5      0.827   0.712  0.942 SS    2019-09-04 m           
#>  6      1.02    0.914  1.12  PK    2019-09-04 m           
#>  7      1.36    1.20   1.43  RK    2019-09-04 m           
#>  8     -0.891  -0.894 -0.793 BE    2019-09-04 g           
#>  9     -0.387  -0.556 -0.218 SG    2019-09-04 g           
#> 10     -0.501  -0.681 -0.321 HM    2019-09-04 g           
#> # ... with 19 more rows

this code

wf.team <- ggplot(fish_team, aes(x=Datum, y=schätzung, group=interaction(Team, schaetz_type), color=schaetz_type))+ 
  geom_errorbar(aes(ymin=unterer, ymax=oberer), width=.1, 
                position=position_dodge(0.05)) +
  geom_line(aes(x=Datum, y= schätzung)) + 
  geom_point(aes(shape=Team))+
  labs(title="Plot123",x="Date", y = "Position")+
  theme(axis.text.x = element_text(angle = 50, size = 10, vjust = 0.5))
wf.team + theme_classic() + scale_color_manual(values=c('#999999','#E69F00'))

produces this plot


the problem is:

  1. i needed to format "Datum" Column as factor since this code
    data$Datum <- as.Date(data$Datum, format="%d.%m.%Y")
    gave me NAs in the "Datum" column. I dont know why it didnt used to do so
  2. The "Datum" x-axis is still not readable even though i did:
    "theme(axis.text.x = element_text(angle = 50, size = 10, vjust = 0.5))"

Just a couple quick comments now, but more later: In your code, the arguments of the form [aesthetics] = without a value, are ignored, so you should remove them, and your code has color = schaetz_type, but your data has no column called schaetz_type. Also, I'm guessing you would probably like one line per combination of Team and type, so your grouping value should be interaction(Team, type) rather than just Team.

1 Like

Another quick request and comment, @object941: Could you make sure your data's column names match the one's you use in your code? And as to your date issue, if you have the format string match the format of your dates, that should work.

1 Like

Getting closer, @object941 ! Now you can remove the contents of geom_line() since the choices for aes() were made in the original call to ggplot(), and you should add the same position = value to geom_point() as you used in your geom_errorbar() so the point lands on the error bar. Now, since the graph is hard to make sense of, I might recommend adding facet_wrap(~ Team) to break up the graph into subplots by Team. Otherwise, I would just note that your theme_classic() is overriding choices you made in the earlier theme() call. Does that get you almost to what you were hoping for?

@dromano thank you for your comments and your quick guidance. :slight_smile:
this is my current code

wf.team <- ggplot(fish_team, aes(x=Datum, y=schätzung, group=interaction(Team, schaetz_type), color=schaetz_type))+ 
  geom_errorbar(aes(ymin=unterer, ymax=oberer), width=.1, 
                position=position_dodge(0.05)) +
  geom_line() + 
  geom_point(aes(shape=Team), position=position_dodge(0.05))+
  labs(title="Plot123",x="Date", y = "Position")+
  theme(axis.text.x = element_text(angle = 50, size = 10, vjust = 0.5))+
  facet_wrap(~ Team)

-- unfortunately it doesent show the plot, while it doesent show an error message either
-- also, i didnt understandt what you meant by

"And as to your date issue, if you have the format string match the format of your dates, that should work".

I tried as.String() but that resulted in endless repeating values in each cell of the column "datum"

This code creates a plot object named wf.team but doesn't show the plot. To view the plot, you need to execute wf.team.

Do your dates look like the ones in the table you posted above? That is, are they of the form "2019-01-10"? (Meaning, 'full year, two-digit month, two-digit day'?)

oh wow i blushed when i did hit "wf.team" :smiley: it worked though, thanks

yes, the "Datum" values are in the "2019-01-13" format. It doesent really matter though since they were in the date format before i made the analysis so it grouped them right. i dont necessarily need them in the date format for the plot as it still does work in ascending order.

You're welcome, and with the dates in that format, the ordering is 'alphabetical' (character order), which does coincide with date order, but the graph may behave better if they're actually dates. You could try this:

fish_team <- fish_team %>% mutate(Datum = as.Date(Datum))
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.