dear ggploters
I have a question about an old thread
https://groups.google.com/forum/?fromgroups#!searchin/ggplot2/splitString/ggplot2/sg9jA-FeQls/i3GPoiNUzN8J can't reply... don't know why.. so i had to start a new thread
baptiste's code below worked fine in version 0.9.1... but not anymore in 0.9.2
splitString <- function (text, width)
{
if(is.null(text)) return(NULL)
strings <- strsplit(text, " ")[[1]]
newstring <- strings[1]
linewidth <- stringWidth(newstring)
gapwidth <- stringWidth(" ")
availwidth <- convertWidth(width, "inches", valueOnly = TRUE)
for (i in 2:length(strings)) {
width <- stringWidth(strings[i])
if (convertWidth(linewidth + gapwidth + width, "inches",
valueOnly = TRUE) < availwidth) {
sep <- " "
linewidth <- linewidth + gapwidth + width
}
else {
sep <- "\n"
linewidth <- width
}
newstring <- paste(newstring, strings[i], sep = sep)
}
newstring
}
title <- "Marker1 : Similar to AAA80501.1 Lycopersicon esculentum;
unknown; Solanum lycopersicum unknown oxidase-like protein mRNA,
complete cds; similar to hyoscyamine 6beta-hydroxylase: SwissProt
Accession Number P24397, flavavone-3-hydroxylase: PIR Accession Number
S36233, and ethylene forming enzyme: encoded by GenBank Accession
number M90294 ;cl209ct403cn544 ;COMPLETE ;RESISTANCE(6), FLOWER(71),
FRUIT(7)"
theme_title <-
function (width=unit(1, "npc"), family = "", face = "plain", colour =
"black", size = 10,
hjust = 0.5, vjust = 0.5, angle = 0, lineheight = 1.1)
{
vj <- vjust
hj <- hjust
structure(function(label, x = hj, y = vj, ..., vjust = vj,
hjust = hj, default.units = "npc") {
textGrob(splitString(label, width), x, y, hjust = hjust, vjust
= vjust, ...,
default.units = default.units, gp = gpar(fontsize = size,
col = colour, fontfamily = family, fontface = face,
lineheight = lineheight), rot = angle)
}, class = "theme", type = "title", call = match.call())
}
qplot(1:10, 1:10) +
opts(title=title, plot.title=theme_title(width=unit(10, "cm")))
i get an error message:
Element plot.title must be a element_text object.
how can i change baptiste's self made "theme_title" to a working element_text object?
thanx for your help!
greg