crysis405
crysis405

Reputation: 1131

gwidgets ggraphics cutting edge of ggplot

This may be something really obvious, but I am struggling to find a good resource explaining how to use features of gwidgets. With some help I have this script which creates checkboxes which alter a list of file names which are then used to create a plot of the checked files using ggplot. The problem is that the plot is getting cut off at the right edge and I have no idea how to fix this.

EDIT: I see some of you have been busy down-rating me, but now this should work if you run it with the file I provided. I have a suspicion that the problem arises from cairoDevice and the way ggraphics renders the plot.

read.table("foo.csv", header = TRUE, sep = ",", row.names=1)

ggplot(MeanFrameMelt, aes(x=variable, y=value, color=Legend, group=Legend))+ 
  geom_line()+ 
  theme(panel.background = element_rect(fill='NA', colour='black', size = 1), 
        legend.position = "none")+ 
  ylab("Tag Density (mean coverage/bp)")+ 
  xlab("Distance from reference side (bp)")+ 
  scale_x_discrete(breaks=c("V1", "V200", "V400"), labels=c("-10000", "0", "10000"))+ 


GraphFiles <- FileNamesOrig
w <- gwindow("Tag Density Checkboxes", width = 1000)
g <- ggroup(container = w, horizontal = FALSE)
add(g, ggraphics())
lyt <- glayout(container = g, horizontal = FALSE)
print(p)

foo.cvs (this is the MeanFrameMelt)

enter image description here

EDIT 2: This is what the graph looks like for me. I don't know what is going on, I am exporting the data.frame with this command:

write.table(MeanFrameMelt, file="test.cvs", sep=",", col.names=TRUE)

but then when I run it with the exported file I get exactly what agstudy got. The files are supposed to be identical.

enter image description here

EDIT 3:

Tested it with gput (thank you for the suggestion) and now its creating the correct plot: New file

Use dget(file="test.txt")

Upvotes: 1

Views: 807

Answers (1)

agstudy
agstudy

Reputation: 121626

I just reorganized your code, but I can't reproduce the problem. You have to call the plot actions inside a handelr to interact later with user(e.g zoom , mouse events). I show an example here. First time you run you have the plot with an ugly axis. Then when you click in a region , the plot is refreshed and you have a nice axis.

## I define my plot
p <- ggplot(MeanFrameMelt, aes(x=variable, y=value, color=Legend, group=Legend))+ 
  geom_line()+ 
  theme(panel.background = element_rect(fill='NA', colour='black', size = 1), 
        legend.position = "none")+ 
  ylab("Tag Density (mean coverage/bp)")+ 
  xlab("Distance from reference side (bp)")
## init gwidgets
library(gWidgetsRGtk2)
w   <- gwindow("Tag Density Checkboxes", width = 1000)
g   <- ggroup(container = w, horizontal = FALSE)
gg  <- ggraphics(container=g)
lyt <- glayout(container = g, horizontal = FALSE)
## I plot it the first time 
print(p)
## I add a handler
ID <- addHandlerChanged(gg, handler=function(h,...) {
   p <-  p + scale_x_discrete(breaks=c("V1", "V200", "V400"), 
                     labels=c("-1000", "0", "1000"))
   print(p)
})
print(p)

enter image description here

Upvotes: 1

Related Questions