简体   繁体   English

对箱线图对象进行更改

[英]making changes on boxplot objects

these are my codes:这些是我的代码:

ggplot(summer.months, aes(x = month, y = Temp_mean, linetype = position, color = canopy, fill = position)) +
  geom_boxplot() +
  theme_bw() +
  ggtitle(" Temperature changes in elevated and lying deadwood in summer under different canopies") +
  labs(y = "temperature values(C°)", x = "months") +
  scale_fill_manual(values = c("white", "white", "green", "black"))

我的图表

my professor said:我的教授说:

i have to put number of objects on the legend on the graph and put the legend on the upper right-hand corner of the graph & make the legend bigger.我必须在图上的图例上放置对象的数量,并将图例放在图的右上角并使图例变大。

put the months in a chronological order like 11,12,1,2,3,4.. ( put the names of the months in the graph instead of numbers)将月份按时间顺序排列,如 11、12、1、2、3、4 ..(将月份的名称而不是数字放在图表中)

i created a basic ggplot but the problem is i can´t do the changes that they want from me cuz the names and order of the objects are so in my excel data.我创建了一个基本的 ggplot,但问题是我不能做他们想要我做的更改,因为对象的名称和顺序在我的 excel 数据中也是如此。

A dput(head(summer.months) ) might be sufficient.一个dput(head(summer.months) ) 可能就足够了。 Anyway, here's an example using internal dataset mpg for illustrating few adjustments:无论如何,这是一个使用内部数据集mpg来说明一些调整的示例:

    library(tidyverse)
    
    ## changing variable for x-Axis into ordered factor - this is a bit of a workaround. If using dates,
    ## it is better to use datatype date and adjust axis labels accordingly
    my_mpg <- mpg %>%
        mutate(class = factor(class, levels = c("compact", "midsize", "suv", "2seater", "minivan", "pickup", "subcompact"), ordered = TRUE))
    
    
    ggplot(my_mpg, aes(x = class, y = hwy, linetype = class, colour = fl, fill = drv)) +
        geom_boxplot() +
        scale_fill_manual(values = c("white", "white", "green", "black")) +
        ## using subtitle to add information about the dataset
        labs(title = "title", subtitle = paste("#lines: ", nrow(mpg))) +
        theme_bw() +
        theme(legend.justification  = "top",             ## move legend to top
            legend.text = element_text(size = 10),       ## adjust text sizes in legend
            legend.title = element_text(size =10),
            legend.key.size = unit(20, "pt"),            ## if required: adjust size of legend keys
            plot.subtitle = element_text(hjust = 1.0))   ## shift subtitle to the right

You might find further hints in ggplot2 reference and the ggplot2 book .您可能会在ggplot2 参考资料ggplot2 书中找到更多提示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM