Skip to content

Error in graph when facets added #10278

@rdstern

Description

@rdstern

@lilyclements this seems to be an error in the databook_get_object_data function.

I will send the data, when you are ready, via whatsapp. It is the second data frame with 30 rows and 18 variables.
I am doing a scatterplot as follows:

Image

This works fine, either from the dialog, or the script:

# Dialog: Scatter Plot

educake_student_league_table_11i1chemistry <- data_book$get_data_frame(data_name="educake_student_league_table_11i1chemistry")
last_graph <- ggplot2::ggplot(data=educake_student_league_table_11i1chemistry, mapping=ggplot2::aes(colour=Science.GCSE.Target...34, y=Chemistry.paper.1.yr.11.Mock.., x=Qs.Answered)) + 
ggplot2::geom_point(size=3.0) + ggplot2::geom_smooth(method="lm", se=TRUE) + theme_grey() + 
ggplot2::theme(legend.position="right")
data_book$add_object(data_name="educake_student_league_table_11i1chemistry", object_name="last_graph", object_type_label="graph", object_format="image", object=instatExtras::check_graph(graph_object=last_graph))
data_book$get_object_data(data_name="educake_student_league_table_11i1chemistry", object_name="last_graph", as_file=TRUE)
rm(list=c("last_graph", "educake_student_league_table_11i1chemistry"))

It gives a single messy graph:

Image

So I included the same variable as facets:

# Dialog: Scatter Plot

educake_student_league_table_11i1chemistry <- data_book$get_data_frame(data_name="educake_student_league_table_11i1chemistry")
last_graph <- ggplot2::ggplot(data=educake_student_league_table_11i1chemistry, mapping=ggplot2::aes(colour=Science.GCSE.Target...34, y=Chemistry.paper.1.yr.11.Mock.., x=Qs.Answered)) + ggplot2::geom_point(size=3.0) + 
ggplot2::geom_smooth(method="lm", se=TRUE) + 
theme_grey() + ggplot2::theme(legend.position="right") + 
ggplot2::facet_wrap(facets=ggplot2::vars(Science.GCSE.Target...34), dir="h")
data_book$add_object(data_name="educake_student_league_table_11i1chemistry", object_name="last_graph", object_type_label="graph", object_format="image", object=instatExtras::check_graph(graph_object=last_graph))
data_book$get_object_data(data_name="educake_student_league_table_11i1chemistry", object_name="last_graph", as_file=TRUE)
rm(list=c("last_graph", "educake_student_league_table_11i1chemistry"))

This just adds the facet wrap line in the code. The databook_get_object_data (which seems identical to before) now gives an error, as follows:

---------------------------
Error running R command(s)
---------------------------
Error in `[.data.frame`(y, by) : undefined columns selected



The error occurred in attempting to run the following R command(s):

educake_student_league_table_11i1chemistry <- data_book$get_data_frame(data_name="educake_student_league_table_11i1chemistry")

last_graph <- ggplot2::ggplot(data=educake_student_league_table_11i1chemistry, mapping=ggplot2::aes(colour=Science.GCSE.Target...34, x=Qs.Answered, y=Chemistry.paper.1.yr.11.Mock..)) + ggplot2::geom_point(size=3.0) + ggplot2::geom_smooth(method="lm", se=TRUE) + theme_grey() + ggplot2::theme(legend.position="right") + ggplot2::facet_wrap(facets=ggplot2::vars(Science.GCSE.Target...34), dir="h")

data_book$add_object(data_name="educake_student_league_table_11i1chemistry", object_name="last_graph", object_type_label="graph", object_format="image", object=instatExtras::check_graph(graph_object=last_graph))

.temp_val <- data_book$get_object_data(data_name="educake_student_league_table_11i1chemistry", object_name="last_graph", as_file=TRUE)
---------------------------
OK   
---------------------------

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions