{"action":"created","issue":{"url":"https://api.github.com/repos/joey711/phyloseq/issues/542","labels_url":"https://api.github.com/repos/joey711/phyloseq/issues/542/labels{/name}","comments_url":"https://api.github.com/repos/joey711/phyloseq/issues/542/comments","events_url":"https://api.github.com/repos/joey711/phyloseq/issues/542/events","html_url":"https://github.com/joey711/phyloseq/issues/542","id":112498654,"number":542,"title":"Trouble plotting factor","user":{"login":"beseekay","id":15223572,"avatar_url":"https://avatars.githubusercontent.com/u/15223572?v=3","gravatar_id":"","url":"https://api.github.com/users/beseekay","html_url":"https://github.com/beseekay","followers_url":"https://api.github.com/users/beseekay/followers","following_url":"https://api.github.com/users/beseekay/following{/other_user}","gists_url":"https://api.github.com/users/beseekay/gists{/gist_id}","starred_url":"https://api.github.com/users/beseekay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/beseekay/subscriptions","organizations_url":"https://api.github.com/users/beseekay/orgs","repos_url":"https://api.github.com/users/beseekay/repos","events_url":"https://api.github.com/users/beseekay/events{/privacy}","received_events_url":"https://api.github.com/users/beseekay/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-10-21T02:26:23Z","updated_at":"2015-10-29T21:01:29Z","closed_at":null,"body":"Hi,\r\nI am having a similar problems to #541, but not the same. I was doing the distance tutorial, and just exchanging the enterotype data with my previously loaded phyloseq object, I had run it through the import data and heat map tutorials and was using a subset created there.\r\n\r\nThis is the script from the tutorial with data and variables changed.\r\n\r\nplist <- vector(\"list\", length(dist_methods))\r\nnames(plist) = dist_methods\r\nfor (i in dist_methods) {\r\n  # Calculate distance matrix\r\n  iDist <- distance(bdcmrp, method = i)\r\n  # Calculate ordination\r\n  iMDS <- ordinate(bdcmrp, \"MDS\", distance = iDist)\r\n  ## Make plot Don't carry over previous plot (if error, p will be blank)\r\n  p <- NULL\r\n  # Create plot, store as temp variable, p\r\n  p <- plot_ordination(bdcmrp, iMDS, color = \"Site\", shape = \"Species\")\r\n  # Add title to each plot\r\n  p <- p + ggtitle(paste(\"MDS using distance method \", i, sep = \"\"))\r\n  # Save the graphic to file.\r\n  plist[[i]] = p\r\n}\r\n\r\nfollowed by\r\n\r\ndf = ldply(plist, function(x) x$data)\r\nnames(df)[1] <- \"distance\"\r\np = ggplot(df, aes(Axis.1, Axis.2, color = \"Site\", shape = \"Species\"))\r\np = p + geom_point(size = 3, alpha = 0.5)\r\np = p + facet_wrap(~distance, scales = \"free\")\r\np = p + ggtitle(\"MDS with various distance metrics for soil sample 16s dataset\")\r\np\r\n\r\nThe data set I am using has the same structure as the enterotype data for the variables I was using, except that site was listed as a integer after importation instead of a factor.\r\n\r\nThe plot legend, with the second part as shown above, listed Site and Species in quotes, and with single points and the plotted points were all the same. If I took the quotes off in the second function it listed the species, and showed the sites as a scale from 1-3. I then changed the site sample variable to a factor, and tried again, and it was unchanged. I tried renaming the variable levels \"Site 1\", \"Site 2\", etc. It then didn't show site in the legend, instead showing sample numbers with one colour each. I reverted the site levels to 1-3, but it is still printing only sample numbers.\r\n\r\nWhen I tried to print out single dm plots, it listed listed sample numbers also, changing the quote status in the plist function, the variable was also not recognized.\r\n\r\n The tutorial data used a factor variable for the color also, so I don't understand what went wrong, any ideas how to fix this?"},"comment":{"url":"https://api.github.com/repos/joey711/phyloseq/issues/comments/152324790","html_url":"https://github.com/joey711/phyloseq/issues/542#issuecomment-152324790","issue_url":"https://api.github.com/repos/joey711/phyloseq/issues/542","id":152324790,"user":{"login":"zachcp","id":1260667,"avatar_url":"https://avatars.githubusercontent.com/u/1260667?v=3","gravatar_id":"","url":"https://api.github.com/users/zachcp","html_url":"https://github.com/zachcp","followers_url":"https://api.github.com/users/zachcp/followers","following_url":"https://api.github.com/users/zachcp/following{/other_user}","gists_url":"https://api.github.com/users/zachcp/gists{/gist_id}","starred_url":"https://api.github.com/users/zachcp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zachcp/subscriptions","organizations_url":"https://api.github.com/users/zachcp/orgs","repos_url":"https://api.github.com/users/zachcp/repos","events_url":"https://api.github.com/users/zachcp/events{/privacy}","received_events_url":"https://api.github.com/users/zachcp/received_events","type":"User","site_admin":false},"created_at":"2015-10-29T21:01:29Z","updated_at":"2015-10-29T21:01:29Z","body":"HI @beseekay ,\r\n\r\nI think you have at least two things going on here.\r\n\r\n1) `aes` vs `aes_string` see the [ggplot docs](http://docs.ggplot2.org/current/)\r\n\r\n```R\r\n#in aes you are mixing column names and strings\r\np = ggplot(df, aes(Axis.1, Axis.2, color = \"Site\", shape = \"Species\"))\r\n# try this instead\r\np = ggplot(df, aes_string(x=\"Axis.1\", y=\"Axis.2\", color = \"Site\", shape = \"Species\"))\r\n# or this\r\np = ggplot(df, aes(x=Axis.1, y=Axis.2, color = Site, shape = Species))\r\n```\r\n\r\n2) numeric vs character. ggplot will interpret numerical columns as continuous and not as categorical.\r\n```R\r\n#convert your numbers to samplenames\r\ndf$Site <- as.character(df$Site)\r\n```\r\n\r\nThere may be other suggestions as well but you would need to provide `df`\r\n\r\ngood luck,\r\nzach cp\r\n\r\n\r\n"}}