本文介绍了格子图标题中的斜体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了有关如何在图形标题中创建斜体字的帖子,但是它似乎对我不起作用.

I have read the posts on how to create italicized words in a graph title, but it does not seem to be working for me.

#create a list of species
sp <- c("Etelis coruscans","Etelis carbunculus","Pristipomoides sieboldii","Pristipomoides filamentosus","Pristipomoides zonatus","Epinephelus quernus","Aphareus rutilans")

#plot hisotgrams for each spp in 1cm bins
for (i in sp){
    BIN_WIDTH <- 1 #desired bin width
    print(histogram(~ Length..cm. | Method, #create and print the histogram and save to variable "graph"
    data = hist.data[hist.data$Scientific_name == i,], 
    nint = (max(hist.data$Length..cm.) - min(hist.data$Length..cm.)+1)/BIN_WIDTH,
    layout = c(1,2),
    main = paste("Length-Frequency of", italic(i), "by Gear"), sep = " ",
    xlab = "Length (cm)"))

    #save histogram to PNG file
    quartz.save(paste("*Length-Frequency of", i, "by method.png", sep = " "), type = "png")
    dev.off() #close the graphics diver
}

我收到一条错误消息:

Error in print(histogram(~Length..cm. | Method, data = hist.data[hist.data$Scientific_name ==  : 
  error in evaluating the argument 'x' in selecting a method for function 'print': Error in paste(italic("Length-Frequency of", i, "by Gear")) : 
  could not find function "italic"

有人可以指出我做错了什么吗?

Can someone point out what I have done wrong?

推荐答案

您传递给main的参数需要进行一些更改.

There argument you are passing to main needs a couple of changes.

  • 要使用R的特殊绘图方法(例如italic()之类的东西),它应该是一个表达式对象而不是字符串.那意味着要做这样的事情:

  • To use R's plotmath specials (i.e. things like italic()), it should be an expression object rather than a character string. That means doing something like this:

main = expression(paste("Length-Freq of", italic("E. coruscans"), "by Gear"))

代替此:

main = paste("Length-Freq of", italic("E. coruscans"), "by Gear")

  • 此外,您想将i斜体而不是其名称,但是,如果您只键入italic(i),则点阵将将每个物种的i名称渲染为小写斜体" i ".使用bquote()substitute()代替i的值,如下所示:

  • In addition, you are wanting to italicize i's value rather than its name, but if you just type italic(i), lattice will render i's name as a little italic "i" for each species. Use bquote() or substitute() to substitute in i's value instead, as demonstrated here:

    i <- "E. coruscans"
    xyplot(1:10~1:10,
        main = substitute(expr = expression(paste("Species name: ", italic(i))), 
                          env = list(i=i)))
    

  • 这篇关于格子图标题中的斜体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    09-25 14:38