IDEMSInternational / R-Instat

A statistics software package powered by R
http://r-instat.org/
GNU General Public License v3.0
38 stars 103 forks source link

Correct and hopefully also improve the Describe > One Variable > Graph dialogue #7821

Open rdstern opened 2 years ago

rdstern commented 2 years ago

As with the stem plot I suggest this is for @N-thony to allocate.

In this dialogue the default bar chart can be pretty bad. Here it is for the field variable in the survey, made into a factor, and flipped. Note it is in character, rather than the factor (numerical) order. In an ordinary factor like the variety it ignores the order of levels and just uses its own alphabetical.

image

Here is the code:

# Code généré par la boîte de dialogue, One Variable Graph
last_graph <- data_book$graph_one_variable(data_name="survey", columns="field", numeric="violin_jitter", categorical="geom_bar", coord_flip=TRUE)
data_book$add_graph(graph_name="last_graph", graph=last_graph, data_name="survey")
data_book$get_graphs(data_name="survey", graph_name="last_graph")

I can't see what is wrong, because it is in our own graph_one_variable code.

Once this is corrected, it would be good to check other other options and also see if there can be useful additions to the dialogue. Being able to add labels on the bar charts would be welcome.

lilyclements commented 2 years ago

@rdstern - @Vitalis95 and I looked at this issue together and have fixed it so that if one column is selected, the y-axis is in the correct order. However, if more than one column is selected, then the y-axis is converted to a character variable because there are now factor levels from multiple variables; for example:

image

image

Do you have a better idea for a solution when more than one character variable is selected (aside from creating multiple plots and using grid.arrange)?

The PR is #7831

rdstern commented 2 years ago

@lilyclements I can live with that - I suppose - for the example above. But here is your solution for 4 variables without the Flip. image

Giving the following: image

So, in this dialogue it is only applying the facetting to the y-axis. Not the x. So there is no need to make it into a character here. Let's leave them as factors.

So, when flipping, let's just apply the facetting idea to the x-axis instead?

lilyclements commented 2 years ago

@rdstern sounds good to me. @N-thony have you assigned this to anyone?

N-thony commented 2 years ago

@rdstern sounds good to me. @N-thony have you assigned this to anyone?

@lilyclements yes, this was asssigned to @Vitalis95. @Vitalis95 can you give an update on this?

Vitalis95 commented 2 years ago

@N-thony , on this issue , there was already a PR #7831 which @lilyclements closed I will reach out to @lilyclements , the function we had added initially converted the y-axis to a character variable if more than one column is selected, it should be left as factors

lilyclements commented 2 years ago

@N-thony , on this issue , there was already a PR #7831 which @lilyclements closed I will reach out to @lilyclements , the function we had added initially converted the y-axis to a character variable if more than one column is selected, it should be left as factors

Not sure why I closed this - think it was an accidental closure. It is now reopened