C, 259 231 Bytes
Golfed Code
#define v a[1][i
i,k,l,x,h,w;main(char*s,char**a){for(;v];w+=2*!x,s=v++],h=x>h?x:h)x=(s==v])*(x+1);h++;s=malloc((x=h++*++w+1)+w);memset(s,32,h*w);for(i=k;v];s[x+1]=s[x]=k=v++],x=k==v]?x-w:(h-1)*w+l++*2+3)s[i*w]=10;printf("%s",s);}
Verbose Code
//Variable Explanations:
//i - increment through argument string, must beinitialized to 0
//k - increment through argument string, must be initialized to 0
//l - record x coordinate in return value, must be initialized to 0
//x - record the actual character position within the return string
//arrheight - the height of the return string
//arrwidth - the width of the return string
//arr - the return string
//argv - the string containing the arguments
#define v argv[1][i
i,k,l,x,arrheight,arrwidth;
main(char*arr,char**argv){
for(;v]; //For Length of input
arrwidth+=2*!x, //increment width by 2 if this char is not the same as the last
arr=v++], //set arr to current char
arrheight=x>arrheight?x:arrheight //see if x is greater than the largest recorded height
)x=(arr==v])*(x+1); //if this character is the same as the last, increment x (using arr to store previous char)
arrheight++; //increment height by one since its 0 indexed
arr=malloc((x=arrheight++*++arrwidth+1)+arrwidth); //create a flattened array widthxheight and set x to be the bottom left position
memset(arr,32,arrheight*arrwidth); //fill array with spaces
for(i=k;v]; //For Length of input
arr[x+1]=arr[x]=k=v++], //set x and x+1 positions to the current character, store current character in i
x=k==v]?x-arrwidth:(arrheight-1)*arrwidth+l++*2+3 //if next char is same as current move vertically, else set x to bottom of next column
)arr[i*arrwidth]=10; //Add new lines to string at end of width
printf("%s",arr); //output string
}
Compiled with GCC, no special Flags
Edit
Saved 28 bytes thanks to adelphus. His change allowed me to create a define. And I made the while loops into for loops to save 2 bytes each by rearranging the loop. I also fixed an issue where the code would break when the last character in input wasn't singleton. The code will fail if there is only one unique letter but should work in all other cases.
aaabbbbaa
? \$\endgroup\$